From cd43a73710ae1f0aa9a82640cf10c8ab9a7fa9a6 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 7 Apr 2010 14:04:48 +0000 Subject: [PATCH] Monotone-Parent: 3d66d23639769946e3c2badd40d0861b60c6cff8 Monotone-Revision: 7346726a0f54ccee6cdcb46da66c4b48bfa8ab67 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-04-07T14:04:48 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 16 +++++ SoObjects/Mailer/SOGoMailAccount.m | 2 +- SoObjects/Mailer/SOGoMailFolder.m | 98 ++++++++++++++---------------- 3 files changed, 64 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7748202dd..4c7a355d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2010-04-07 Wolfgang Sourdeau + + * SoObjects/Mailer/SOGoMailFolder.m (-toManyRelationshipKeys): we + now check if the mailbox exists before returning the message + identifiers. + (-lookupName:inContext:acquire:): we no longer check whether the + folder exists as it causes problems when it is a "noselect" parent + folder. Existence of folders is thus checked only when messages + are accessed. + + * SoObjects/Mailer/SOGoMailAccount.m + (_appendNamespace:toFolders:): it may happen that the namespace + "folders" have already been added via the list command, therefore + we now ensure that the folder names do not already exist before + adding them to the array. + 2010-04-06 Wolfgang Sourdeau * UI/WebServerResources/UIxPreferences.js (prototypeIfyFilters): diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index ea025a45e..74cd6ea67 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -112,7 +112,7 @@ static NSString *sieveScriptName = @"sogo"; newFolder = [[currentPart objectForKey: @"prefix"] substringFromIndex: 1]; if ([newFolder length]) - [folders addObject: newFolder]; + [folders addObjectUniquely: newFolder]; } } diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 24468d62f..5979d3472 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -243,17 +243,20 @@ static NSString *defaultUserID = @"anyone"; if (!filenames) { filenames = [NSMutableArray new]; - uids = [self fetchUIDsMatchingQualifier: nil sortOrdering: @"DATE"]; - if (![uids isKindOfClass: [NSException class]]) - { - max = [uids count]; - for (count = 0; count < max; count++) - { - filename = [NSString stringWithFormat: @"%@.eml", - [uids objectAtIndex: count]]; - [filenames addObject: filename]; - } - } + if ([[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]]) + { + uids = [self fetchUIDsMatchingQualifier: nil sortOrdering: @"DATE"]; + if (![uids isKindOfClass: [NSException class]]) + { + max = [uids count]; + for (count = 0; count < max; count++) + { + filename = [NSString stringWithFormat: @"%@.eml", + [uids objectAtIndex: count]]; + [filenames addObject: filename]; + } + } + } } return filenames; @@ -494,11 +497,11 @@ static NSString *defaultUserID = @"anyone"; { // We check for the existence of the IMAP folder (likely to be the // Sent mailbox) prior to appending messages to it. - if ([[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]] || - ![[self imap4Connection] createMailbox: [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]] - atURL: [[self mailAccountFolder] imap4URL]]) + if ([[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]] + || ![[self imap4Connection] createMailbox: [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]] + atURL: [[self mailAccountFolder] imap4URL]]) return [[self imap4Connection] postData: _data flags: _flags - toFolderURL: [self imap4URL]]; + toFolderURL: [self imap4URL]]; return [NSException exceptionWithHTTPStatus: 502 /* Bad Gateway */ reason: [NSString stringWithFormat: @"%@ is not an IMAP4 folder", [self relativeImap4Name]]]; @@ -576,47 +579,40 @@ static NSString *defaultUserID = @"anyone"; SOGoMailAccount *mailAccount; id obj; - // We automatically create mailboxes that don't exist but that we're - // trying to open. This shouldn't happen unless a mailbox has been - // deleted "behind our back" or if we're trying to open a special - // mailbox that doesn't yet exist. - if ([[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]] - || ![[self imap4Connection] createMailbox: [self relativeImap4Name] - atURL: [[self mailAccountFolder] imap4URL]]) + obj = [super lookupName: _key inContext: _ctx acquire: NO]; + if (!obj) { - obj = [super lookupName: _key inContext: _ctx acquire: NO]; - if (!obj) + if ([_key hasPrefix: @"folder"]) { - if ([_key hasPrefix: @"folder"]) - { - mailAccount = [self mailAccountFolder]; - folderName = [[_key substringFromIndex: 6] fromCSSIdentifier]; - fullFolderName = [NSString stringWithFormat: @"%@/%@", - [self traversalFromMailAccount], folderName]; - if ([fullFolderName - isEqualToString: [mailAccount sentFolderNameInContext: _ctx]]) - className = @"SOGoSentFolder"; - else if ([fullFolderName isEqualToString: - [mailAccount draftsFolderNameInContext: _ctx]]) - className = @"SOGoDraftsFolder"; - else if ([fullFolderName isEqualToString: - [mailAccount trashFolderNameInContext: _ctx]]) - className = @"SOGoTrashFolder"; - /* else if ([folderName isEqualToString: - [mailAccount sieveFolderNameInContext: _ctx]]) - obj = [self lookupFiltersFolder: _key inContext: _ctx]; */ - else - className = @"SOGoMailFolder"; + mailAccount = [self mailAccountFolder]; + folderName = [[_key substringFromIndex: 6] fromCSSIdentifier]; + fullFolderName = [NSString stringWithFormat: @"%@/%@", + [self traversalFromMailAccount], folderName]; + if ([fullFolderName + isEqualToString: + [mailAccount sentFolderNameInContext: _ctx]]) + className = @"SOGoSentFolder"; + else if ([fullFolderName + isEqualToString: + [mailAccount draftsFolderNameInContext: _ctx]]) + className = @"SOGoDraftsFolder"; + else if ([fullFolderName + isEqualToString: + [mailAccount trashFolderNameInContext: _ctx]]) + className = @"SOGoTrashFolder"; + /* else if ([folderName isEqualToString: + [mailAccount sieveFolderNameInContext: _ctx]]) + obj = [self lookupFiltersFolder: _key inContext: _ctx]; */ + else + className = @"SOGoMailFolder"; - obj = [NSClassFromString (className) objectWithName: _key - inContainer: self]; - } - else if (isdigit ([_key characterAtIndex: 0])) - obj = [SOGoMailObject objectWithName: _key inContainer: self]; + obj = [NSClassFromString (className) objectWithName: _key + inContainer: self]; } + else if (isdigit ([_key characterAtIndex: 0]) + && [[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]]) + obj = [SOGoMailObject objectWithName: _key inContainer: self]; } - else - obj = nil; if (!obj && _acquire) obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];