diff --git a/SoObjects/Mailer/SOGoMailAccount.h b/SoObjects/Mailer/SOGoMailAccount.h index 1c229cd38..58f80cf45 100644 --- a/SoObjects/Mailer/SOGoMailAccount.h +++ b/SoObjects/Mailer/SOGoMailAccount.h @@ -78,6 +78,7 @@ typedef enum { - (BOOL) hasCapability: (NSString *) capability; - (BOOL) supportsQuotas; - (BOOL) supportsQResync; +- (BOOL) supportsMove; - (id) getInboxQuota; - (NSException *) updateFilters; diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index fdc6f868d..d7d4198ed 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -267,6 +267,11 @@ static NSString *inboxFolderName = @"INBOX"; return [self hasCapability: @"qresync"]; } +- (BOOL) supportsMove +{ + return [self hasCapability: @"move"]; +} + - (id) getInboxQuota { SOGoMailFolder *inbox; diff --git a/SoObjects/Mailer/SOGoMailFolder.h b/SoObjects/Mailer/SOGoMailFolder.h index 0ae2430cb..f9d0cec70 100644 --- a/SoObjects/Mailer/SOGoMailFolder.h +++ b/SoObjects/Mailer/SOGoMailFolder.h @@ -70,6 +70,10 @@ - (NSArray *) fetchUIDs: (NSArray *) _uids parts: (NSArray *) _parts; - (NSArray *) fetchUIDsOfVanishedItems: (uint64_t) modseq; +- (WOResponse *) moveUIDs: (NSArray *) uids + toFolder: (NSString *) destinationFolder + inContext: (id) localContext + keepCopy: (BOOL) copy; - (WOResponse *) copyUIDs: (NSArray *) uids toFolder: (NSString *) destinationFolder inContext: (id) localContext; diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 812814091..11c404c6d 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -636,6 +636,27 @@ static NSComparisonResult _compareFetchResultsByUID (id entry1, id entry2, NSArr - (WOResponse *) copyUIDs: (NSArray *) uids toFolder: (NSString *) destinationFolder inContext: (id) localContext +{ + return [self moveUIDs: uids + toFolder: destinationFolder + inContext: localContext + keepCopy: YES]; +} + +- (WOResponse *) moveUIDs: (NSArray *) uids + toFolder: (NSString *) destinationFolder + inContext: (id) localContext +{ + return [self moveUIDs: uids + toFolder: destinationFolder + inContext: localContext + keepCopy: NO]; +} + +- (WOResponse *) moveUIDs: (NSArray *) uids + toFolder: (NSString *) destinationFolder + inContext: (id) localContext + keepCopy: (BOOL) copy { NSArray *folders; NSString *currentFolderName, *currentAccountName, *destinationAccountName; @@ -673,15 +694,35 @@ static NSComparisonResult _compareFetchResultsByUID (id entry1, id entry2, NSArr result = [[self imap4Connection] createMailbox: imapDestinationFolder atURL: [[self mailAccountFolder] imap4URL]]; if (!result || [result boolValue]) - result = [client copyUids: uids toFolder: imapDestinationFolder]; + { + if (copy || ![[self mailAccountFolder] supportsMove]) + result = [client copyUids: uids toFolder: imapDestinationFolder]; + else + result = [client moveUids: uids toFolder: imapDestinationFolder]; + } if ([[result valueForKey: @"result"] boolValue]) - result = nil; + { + result = nil; + if (!copy && ![[self mailAccountFolder] supportsMove]) + { + // Server doesn't support MOVE -- delete messages + result = [client storeFlags: [NSArray arrayWithObject: @"Deleted"] + forUIDs: uids addOrRemove: YES]; + if ([[result valueForKey: @"result"] boolValue]) + { + [self markForExpunge]; + result = nil; + } + } + } else - result = [NSException exceptionWithHTTPStatus: 500 - reason: [[[result objectForKey: @"RawResponse"] - objectForKey: @"ResponseResult"] - objectForKey: @"description"]]; + { + result = [NSException exceptionWithHTTPStatus: 500 + reason: [[[result objectForKey: @"RawResponse"] + objectForKey: @"ResponseResult"] + objectForKey: @"description"]]; + } } else { @@ -759,36 +800,6 @@ static NSComparisonResult _compareFetchResultsByUID (id entry1, id entry2, NSArr return result; } -- (WOResponse *) moveUIDs: (NSArray *) uids - toFolder: (NSString *) destinationFolder - inContext: (id) localContext -{ - id result; - NGImap4Client *client; - - client = [[self imap4Connection] client]; - if (client) - { - result = [self copyUIDs: uids toFolder: destinationFolder inContext: localContext]; - if (![result isNotNull]) - { - result = [client storeFlags: [NSArray arrayWithObject: @"Deleted"] - forUIDs: uids addOrRemove: YES]; - if ([[result valueForKey: @"result"] boolValue]) - { - [self markForExpunge]; - result = nil; - } - } - } - else - result = [NSException exceptionWithName: @"SOGoMailException" - reason: @"IMAP connection is invalid" - userInfo: nil]; - - return result; -} - - (WOResponse *) markMessagesAsJunkOrNotJunk: (NSArray *) uids junk: (BOOL) isJunk {