diff --git a/ChangeLog b/ChangeLog index 8c06660f0..89689825a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-03-13 Ludovic Marcotte + + * Optimized the IMAP client code to avoid + unnecessary STATUS calls. + 2009-03-12 Ludovic Marcotte * Updated the SOPE patchset in order to diff --git a/SoObjects/Mailer/SOGoDraftObject.m b/SoObjects/Mailer/SOGoDraftObject.m index e36d98348..67f52bf9c 100644 --- a/SoObjects/Mailer/SOGoDraftObject.m +++ b/SoObjects/Mailer/SOGoDraftObject.m @@ -388,6 +388,13 @@ static BOOL showTextAttachmentsInline = NO; message = [self mimeMessageAsData]; client = [[self imap4Connection] client]; + + if (![imap4 doesMailboxExistAtURL: [container imap4URL]]) + { + [client create: [container relativeImap4Name]]; + [imap4 flushFolderHierarchyCache]; + } + folder = [imap4 imap4FolderNameForURL: [container imap4URL]]; result = [client append: message toFolder: folder diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 6d6274c05..11e5857a6 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -1,14 +1,15 @@ /* Copyright (C) 2004-2005 SKYRIX Software AG + Copyright (C) 2007-2009 Inverse inc. - This file is part of OpenGroupware.org. + This file is part of SOGo. - OGo is free software; you can redistribute it and/or modify it under + SOGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - OGo is distributed in the hope that it will be useful, but WITHOUT ANY + SOGo 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 Lesser General Public License for more details. @@ -338,8 +339,6 @@ static NSString *fallbackIMAP4Server = nil; else if ([folderName isEqualToString: [self trashFolderNameInContext: _ctx]]) klazz = [SOGoTrashFolder class]; -/* else if ([folderName isEqualToString: [self sieveFolderNameInContext: _ctx]]) - obj = [self lookupFiltersFolder: _key inContext: _ctx]; */ else klazz = [SOGoMailFolder class]; diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 814c8c353..1b0b3d1f4 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -289,7 +289,18 @@ static NSString *spoolFolder = nil; client = [[self imap4Connection] client]; [imap4 selectFolder: [self imap4URL]]; folderName = [imap4 imap4FolderNameForURL: [trashFolder imap4URL]]; - result = [client copyUids: uids toFolder: folderName]; + + // If our Trash folder doesn't exist when we try to copy messages + // to it, we create it. + result = [[client status: folderName flags: [NSArray arrayWithObject: @"UIDVALIDITY"]] + objectForKey: @"result"]; + + if (![result boolValue]) + result = [[self imap4Connection] createMailbox: folderName atURL: [[self mailAccountFolder] imap4URL]]; + + if (!result || [result boolValue]) + result = [client copyUids: uids toFolder: folderName]; + if ([[result valueForKey: @"result"] boolValue]) { result = [client storeFlags: [NSArray arrayWithObject: @"Deleted"] @@ -423,7 +434,15 @@ static NSString *spoolFolder = nil; client = [[self imap4Connection] client]; [imap4 selectFolder: [self imap4URL]]; - result = [client copyUids: uids toFolder: imapDestinationFolder]; + // We make sure the destination IMAP folder exist, if not, we create it. + result = [[client status: imapDestinationFolder flags: [NSArray arrayWithObject: @"UIDVALIDITY"]] + objectForKey: @"result"]; + + if (![result boolValue]) + result = [[self imap4Connection] createMailbox: imapDestinationFolder atURL: [[self mailAccountFolder] imap4URL]]; + + if (!result || [result boolValue]) + result = [client copyUids: uids toFolder: imapDestinationFolder]; if ([[result valueForKey: @"result"] boolValue]) result = nil; @@ -475,8 +494,15 @@ static NSString *spoolFolder = nil; - (NSException *) postData: (NSData *) _data flags: (id) _flags { - return [[self imap4Connection] postData: _data flags: _flags - toFolderURL: [self imap4URL]]; + // 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 relativeImap4Name] atURL: [[self mailAccountFolder] imap4URL]]) + return [[self imap4Connection] postData: _data flags: _flags + toFolderURL: [self imap4URL]]; + + return [NSException exceptionWithHTTPStatus: 502 /* Bad Gateway */ + reason: [NSString stringWithFormat: @"%@ is not an IMAP4 folder", [self relativeImap4Name]]]; } - (NSException *) expunge @@ -577,7 +603,12 @@ static NSString *spoolFolder = nil; } else { - if ([[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]]) + // 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]]) { if (isdigit ([_key characterAtIndex: 0])) obj = [SOGoMailObject objectWithName: _key inContainer: self]; @@ -1069,20 +1100,6 @@ static NSString *spoolFolder = nil; @implementation SOGoSpecialMailFolder -- (id) initWithName: (NSString *) newName - inContainer: (id) newContainer -{ - if ((self = [super initWithName: newName - inContainer: newContainer])) - { - if (![[self imap4Connection] doesMailboxExistAtURL: [self imap4URL]]) - [imap4 createMailbox: [self relativeImap4Name] - atURL: [newContainer imap4URL]]; - } - - return self; -} - - (BOOL) isSpecialFolder { return YES;