diff --git a/ChangeLog b/ChangeLog index 814019819..173fa0945 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,12 @@ 2011-07-15 Wolfgang Sourdeau + * OpenChange/MAPIStoreDraftsAttachment.m: removed useless class. + + * OpenChange/MAPIStoreMessage.m (-createAttachment): moved method + from MAPIStoreDraftsMessage + (-childKeysMatchingQualifier:andSortOrderings:): same as above. + * OpenChange/*.m: make use of mapistore error code rather than MAPI ones. diff --git a/OpenChange/GNUmakefile b/OpenChange/GNUmakefile index a0e7f4a19..28bcea319 100644 --- a/OpenChange/GNUmakefile +++ b/OpenChange/GNUmakefile @@ -81,7 +81,6 @@ $(SOGOBACKEND)_OBJC_FILES += \ MAPIStoreMailContext.m \ MAPIStoreMailFolder.m \ MAPIStoreMailFolderTable.m \ - MAPIStoreDraftsAttachment.m \ MAPIStoreDraftsMessage.m \ MAPIStoreMailMessage.m \ MAPIStoreMailMessageTable.m \ diff --git a/OpenChange/MAPIStoreDraftsAttachment.h b/OpenChange/MAPIStoreDraftsAttachment.h deleted file mode 100644 index 89ba7d105..000000000 --- a/OpenChange/MAPIStoreDraftsAttachment.h +++ /dev/null @@ -1,31 +0,0 @@ -/* MAPIStoreDraftsAttachment.h - this file is part of SOGo - * - * Copyright (C) 2011 Inverse inc - * - * Author: Wolfgang Sourdeau - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef MAPISTOREDRAFTSATTACHMENT_H -#define MAPISTOREDRAFTSATTACHMENT_H - -#import "MAPIStoreAttachment.h" - -@interface MAPIStoreDraftsAttachment : MAPIStoreAttachment -@end - -#endif /* MAPISTOREDRAFTSATTACHMENT_H */ diff --git a/OpenChange/MAPIStoreDraftsAttachment.m b/OpenChange/MAPIStoreDraftsAttachment.m deleted file mode 100644 index 5945e1622..000000000 --- a/OpenChange/MAPIStoreDraftsAttachment.m +++ /dev/null @@ -1,27 +0,0 @@ -/* MAPIStoreDraftsAttachment.m - this file is part of SOGo - * - * Copyright (C) 2011 Inverse inc - * - * Author: Wolfgang Sourdeau - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#import "MAPIStoreDraftsAttachment.h" - -@implementation MAPIStoreDraftsAttachment - -@end diff --git a/OpenChange/MAPIStoreDraftsMessage.m b/OpenChange/MAPIStoreDraftsMessage.m index 7edc5d343..18cfcfffc 100644 --- a/OpenChange/MAPIStoreDraftsMessage.m +++ b/OpenChange/MAPIStoreDraftsMessage.m @@ -30,7 +30,6 @@ #import #import "MAPIStoreContext.h" -#import "MAPIStoreDraftsAttachment.h" #import "MAPIStoreTypes.h" #import "MAPIStoreDraftsMessage.h" @@ -41,17 +40,6 @@ @implementation MAPIStoreDraftsMessage -- (id) init -{ - if ((self = [super init])) - { - attachmentKeys = [NSMutableArray new]; - attachmentParts = [NSMutableDictionary new]; - } - - return self; -} - - (int) getPrMessageFlags: (void **) data inMemCtx: (TALLOC_CTX *) memCtx { @@ -179,38 +167,6 @@ e) [self _saveAttachment: [attachmentKeys objectAtIndex: count]]; } -- (MAPIStoreAttachment *) createAttachment -{ - MAPIStoreDraftsAttachment *newAttachment; - uint32_t newAid; - NSString *newKey; - - newAid = [attachmentKeys count]; - - newAttachment = [MAPIStoreDraftsAttachment - mapiStoreObjectWithSOGoObject: nil - inContainer: self]; - [newAttachment setIsNew: YES]; - [newAttachment setAID: newAid]; - newKey = [NSString stringWithFormat: @"%ul", newAid]; - [attachmentParts setObject: newAttachment - forKey: newKey]; - [attachmentKeys addObject: newKey]; - - return newAttachment; -} - -- (NSArray *) childKeysMatchingQualifier: (EOQualifier *) qualifier - andSortOrderings: (NSArray *) sortOrderings -{ - if (qualifier) - [self errorWithFormat: @"qualifier is not used for attachments"]; - if (sortOrderings) - [self errorWithFormat: @"sort orderings are not used for attachments"]; - - return attachmentKeys; -} - - (id) lookupChild: (NSString *) childKey { return [attachmentParts objectForKey: childKey]; diff --git a/OpenChange/MAPIStoreFSMessage.h b/OpenChange/MAPIStoreFSMessage.h index 03a9b3fb4..d15892fc4 100644 --- a/OpenChange/MAPIStoreFSMessage.h +++ b/OpenChange/MAPIStoreFSMessage.h @@ -26,6 +26,10 @@ #import "MAPIStoreMessage.h" @interface MAPIStoreFSMessage : MAPIStoreMessage +{ + BOOL fetchedAttachments; +} + @end #endif /* MAPISTOREFSMESSAGE_H */ diff --git a/OpenChange/MAPIStoreFSMessage.m b/OpenChange/MAPIStoreFSMessage.m index e385f0232..b84ba4471 100644 --- a/OpenChange/MAPIStoreFSMessage.m +++ b/OpenChange/MAPIStoreFSMessage.m @@ -64,6 +64,14 @@ return MAPISTORE_SUCCESS; } +- (id) init +{ + if ((self = [super init])) + fetchedAttachments = NO; + + return self; +} + - (int) getProperty: (void **) data withTag: (enum MAPITAGS) propTag inMemCtx: (TALLOC_CTX *) memCtx @@ -102,6 +110,7 @@ { NSArray *keys; NSUInteger count, max; + NSString *key; struct SPropTagArray *properties; keys = [[sogoObject properties] allKeys]; @@ -117,12 +126,15 @@ // #elif (GS_SIZEOF_INT == 4) // return [NSNumber numberWithUnsignedInt: propTag]; // #else - + key = [keys objectAtIndex: count]; + if (![key isEqualToString: @"attachments"]) + { #if (GS_SIZEOF_LONG == 4) - properties->aulPropTag[count] = [[keys objectAtIndex: count] unsignedLongValue]; + properties->aulPropTag[count] = [[keys objectAtIndex: count] unsignedLongValue]; #elif (GS_SIZEOF_INT == 4) - properties->aulPropTag[count] = [[keys objectAtIndex: count] unsignedIntValue]; + properties->aulPropTag[count] = [[keys objectAtIndex: count] unsignedIntValue]; #endif + } } *propertiesP = properties; @@ -130,8 +142,42 @@ return MAPISTORE_SUCCESS; } +- (NSArray *) childKeysMatchingQualifier: (EOQualifier *) qualifier + andSortOrderings: (NSArray *) sortOrderings +{ + NSDictionary *attachments; + NSArray *keys; + NSString *key, *newKey; + NSUInteger count, max, aid; + MAPIStoreAttachment *attachment; + + if (!fetchedAttachments) + { + attachments = [[sogoObject properties] objectForKey: @"attachments"]; + keys = [attachments allKeys]; + max = [keys count]; + if (max > 0) + { + aid = [keys count]; + for (count = 0; count < max; count++) + { + key = [keys objectAtIndex: count]; + attachment = [attachments objectForKey: key]; + newKey = [NSString stringWithFormat: @"%ul", (aid + count)]; + [attachmentParts setObject: attachment forKey: newKey]; + } + } + fetchedAttachments = YES; + } + + return [super childKeysMatchingQualifier: qualifier + andSortOrderings: sortOrderings]; +} + - (void) save { + if ([attachmentKeys count] > 0) + [newProperties setObject: attachmentParts forKey: @"attachments"]; [sogoObject appendProperties: newProperties]; [sogoObject save]; [self resetNewProperties]; diff --git a/OpenChange/MAPIStoreMailMessage.h b/OpenChange/MAPIStoreMailMessage.h index 4f8176655..ea9fd2266 100644 --- a/OpenChange/MAPIStoreMailMessage.h +++ b/OpenChange/MAPIStoreMailMessage.h @@ -26,6 +26,9 @@ #import "MAPIStoreMessage.h" @interface MAPIStoreMailMessage : MAPIStoreMessage +{ + BOOL fetchedAttachments; +} @end diff --git a/OpenChange/MAPIStoreMailMessage.m b/OpenChange/MAPIStoreMailMessage.m index 79cb6c936..18ba1c333 100644 --- a/OpenChange/MAPIStoreMailMessage.m +++ b/OpenChange/MAPIStoreMailMessage.m @@ -85,6 +85,14 @@ static Class NSExceptionK, MAPIStoreSentItemsFolderK, MAPIStoreDraftsFolderK; MAPIStoreDraftsFolderK = [MAPIStoreDraftsFolder class]; } +- (id) init +{ + if ((self = [super init])) + fetchedAttachments = NO; + + return self; +} + - (int) getPrIconIndex: (void **) data inMemCtx: (TALLOC_CTX *) memCtx { @@ -786,15 +794,15 @@ static Class NSExceptionK, MAPIStoreSentItemsFolderK, MAPIStoreDraftsFolderK; - (NSArray *) childKeysMatchingQualifier: (EOQualifier *) qualifier andSortOrderings: (NSArray *) sortOrderings { - if (!attachmentKeys) + if (!fetchedAttachments) { - attachmentKeys = [NSMutableArray new]; - attachmentParts = [NSMutableDictionary new]; [self _fetchAttachmentPartsInBodyInfo: [sogoObject bodyStructure] withPrefix: @""]; + fetchedAttachments = YES; } - return attachmentKeys; + return [super childKeysMatchingQualifier: qualifier + andSortOrderings: sortOrderings]; } - (id) lookupChild: (NSString *) childKey diff --git a/OpenChange/MAPIStoreMessage.m b/OpenChange/MAPIStoreMessage.m index 96005ee15..b7dc2f396 100644 --- a/OpenChange/MAPIStoreMessage.m +++ b/OpenChange/MAPIStoreMessage.m @@ -59,8 +59,8 @@ { if ((self = [super init])) { - attachmentKeys = nil; - attachmentParts = nil; + attachmentKeys = [NSMutableArray new]; + attachmentParts = [NSMutableDictionary new]; activeTables = [NSMutableArray new]; } @@ -231,6 +231,27 @@ return MAPISTORE_SUCCESS; } +- (MAPIStoreAttachment *) createAttachment +{ + MAPIStoreAttachment *newAttachment; + uint32_t newAid; + NSString *newKey; + + newAid = [attachmentKeys count]; + + newAttachment = [MAPIStoreAttachment + mapiStoreObjectWithSOGoObject: nil + inContainer: self]; + [newAttachment setIsNew: YES]; + [newAttachment setAID: newAid]; + newKey = [NSString stringWithFormat: @"%ul", newAid]; + [attachmentParts setObject: newAttachment + forKey: newKey]; + [attachmentKeys addObject: newKey]; + + return newAttachment; +} + - (int) createAttachment: (MAPIStoreAttachment **) attachmentPtr inAID: (uint32_t *) aidPtr { @@ -649,11 +670,15 @@ [self subclassResponsibility: _cmd]; } -- (MAPIStoreAttachment *) createAttachment +- (NSArray *) childKeysMatchingQualifier: (EOQualifier *) qualifier + andSortOrderings: (NSArray *) sortOrderings { - [self subclassResponsibility: _cmd]; - - return nil; + if (qualifier) + [self errorWithFormat: @"qualifier is not used for attachments"]; + if (sortOrderings) + [self errorWithFormat: @"sort orderings are not used for attachments"]; + + return attachmentKeys; } - (MAPIStoreAttachmentTable *) attachmentTable