From d2aeeb8240027ba132f31bd5deb1e43e7b88fd08 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 15 Aug 2011 19:25:13 +0000 Subject: [PATCH] Monotone-Parent: 62917484785e9ce38f416c25ad860a0f28f415b0 Monotone-Revision: 78657a62b0fa7fdbe634fe7a1153013d15cba15b Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2011-08-15T19:25:13 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 16 +++++ OpenChange/MAPIStoreMailFolder.h | 4 ++ OpenChange/MAPIStoreMailFolder.m | 109 +++++++++++++++++++++++++++++-- 3 files changed, 124 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index eccb60edb..18d874dc6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ 2011-08-15 Wolfgang Sourdeau + * OpenChange/MAPIStoreMailFolder.m + (-[MAPIStoreMailFolder createFolder:withFID:inContainer:): new method + that enables the specification of a SOGo object container. + (-[MAPIStoreMailFolder createFolder:withFID:): rewritten method to make + use of the above. + (-[MAPIStoreInboxFolder createFolder:withFID:): rewritten method to make + use of the above, with the choice container depending on the + "usesAltNamespace" ivar. + (-[MAPIStoreInboxFolder initWithURL:inContext:): overriden method + to initialize the "usesAltNamespace" ivar based on the flags set + on the "INBOX" folder. + (-[MAPIStoreInboxFolder + folderKeysMatchingQualifier:andSortOrderings:]) + (-[MAPIStoreInboxFolder lookupFolder:]): + overriden methods to make use of "usesAltNamespace". + * SoObjects/Mailer/SOGoMailAccount.m (-toManyRelationshipKeysWithNamespaces:): new method, superseding "toManyRelationshipKeys" that enables the returning of namespaces diff --git a/OpenChange/MAPIStoreMailFolder.h b/OpenChange/MAPIStoreMailFolder.h index 317452c0b..2fec15d3d 100644 --- a/OpenChange/MAPIStoreMailFolder.h +++ b/OpenChange/MAPIStoreMailFolder.h @@ -53,6 +53,10 @@ @end @interface MAPIStoreInboxFolder : MAPIStoreMailFolder +{ + BOOL usesAltNameSpace; +} + @end @interface MAPIStoreSentItemsFolder : MAPIStoreMailFolder diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 2b691679a..e35de2a1d 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -33,6 +33,7 @@ #import #import #import +#import #import #import #import @@ -167,6 +168,7 @@ static Class SOGoMailFolderK; - (NSString *) createFolder: (struct SRow *) aRow withFID: (uint64_t) newFID + inContainer: (id) subfolderParent { NSString *folderName, *nameInContainer; SOGoMailFolder *newFolder; @@ -188,7 +190,7 @@ static Class SOGoMailFolderK; nameInContainer = [NSString stringWithFormat: @"folder%@", [folderName asCSSIdentifier]]; newFolder = [SOGoMailFolderK objectWithName: nameInContainer - inContainer: sogoObject]; + inContainer: subfolderParent]; if (![newFolder create]) nameInContainer = nil; } @@ -196,6 +198,13 @@ static Class SOGoMailFolderK; return nameInContainer; } +- (NSString *) createFolder: (struct SRow *) aRow + withFID: (uint64_t) newFID +{ + return [self createFolder: aRow withFID: newFID + inContainer: sogoObject]; +} + - (int) getPrContentUnread: (void **) data inMemCtx: (TALLOC_CTX *) memCtx { @@ -273,12 +282,15 @@ static Class SOGoMailFolderK; return [uidKeys stringsWithFormat: @"%@.eml"]; } -- (NSArray *) folderKeys +- (NSArray *) folderKeysMatchingQualifier: (EOQualifier *) qualifier + andSortOrderings: (NSArray *) sortOrderings { - if (!folderKeys) - folderKeys = [[sogoObject toManyRelationshipKeys] mutableCopy]; + if (qualifier) + [self errorWithFormat: @"qualifier is not used for folders"]; + if (sortOrderings) + [self errorWithFormat: @"sort orderings are not used for folders"]; - return folderKeys; + return [sogoObject toManyRelationshipKeys]; } - (id) lookupFolder: (NSString *) childKey @@ -558,12 +570,99 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data) @implementation MAPIStoreInboxFolder : MAPIStoreMailFolder +- (id) initWithURL: (NSURL *) newURL + inContext: (MAPIStoreContext *) newContext +{ + NSDictionary *list, *response; + NGImap4Client *client; + + if ((self = [super initWithURL: newURL + inContext: newContext])) + { + client = [[(SOGoMailFolder *) sogoObject imap4Connection] client]; + list = [client list: @"" pattern: @"INBOX"]; + response = [[list objectForKey: @"RawResponse"] objectForKey: @"list"]; + usesAltNameSpace = [[response objectForKey: @"flags"] containsObject: @"noinferiors"]; + } + + return self; +} + - (SOGoMailFolder *) specialFolderFromAccount: (SOGoMailAccount *) accountFolder inContext: (WOContext *) woContext { return [accountFolder inboxFolderInContext: woContext]; } +- (NSString *) createFolder: (struct SRow *) aRow + withFID: (uint64_t) newFID +{ + id subfolderParent; + + if (usesAltNameSpace) + subfolderParent = [(SOGoMailFolder *) sogoObject mailAccountFolder]; + else + subfolderParent = sogoObject; + + return [self createFolder: aRow withFID: newFID + inContainer: subfolderParent]; +} + +- (NSArray *) folderKeysMatchingQualifier: (EOQualifier *) qualifier + andSortOrderings: (NSArray *) sortOrderings +{ + NSMutableArray *subfolderKeys; + SOGoMailAccount *account; + + if (usesAltNameSpace) + { + if (qualifier) + [self errorWithFormat: @"qualifier is not used for folders"]; + if (sortOrderings) + [self errorWithFormat: @"sort orderings are not used for folders"]; + + account = [(SOGoMailFolder *) sogoObject mailAccountFolder]; + subfolderKeys + = [[account toManyRelationshipKeysWithNamespaces: NO] + mutableCopy]; + [subfolderKeys removeObject: @"folderINBOX"]; + } + else + subfolderKeys = [[super folderKeysMatchingQualifier: qualifier + andSortOrderings: sortOrderings] + mutableCopy]; + + /* TODO: remove special folders */ + + [subfolderKeys autorelease]; + + return subfolderKeys; +} + +- (id) lookupFolder: (NSString *) childKey +{ + id childObject = nil; + SOGoMailAccount *account; + SOGoMailFolder *childFolder; + + if (usesAltNameSpace) + { + [self folderKeys]; + if ([folderKeys containsObject: childKey]) + { + account = [(SOGoMailFolder *) sogoObject mailAccountFolder]; + childFolder = [account lookupName: childKey inContext: nil + acquire: NO]; + childObject = [MAPIStoreMailFolder mapiStoreObjectWithSOGoObject: childFolder + inContainer: self]; + } + } + else + childObject = [super lookupFolder: childKey]; + + return childObject; +} + @end @implementation MAPIStoreSentItemsFolder : MAPIStoreMailFolder