diff --git a/NEWS b/NEWS index 37e4ee5ff..fe7e44ba3 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ Enhancements Bug fixes - [eas] fixed long GUID issue preventing sometimes synchronisation (#3460) - [web] improved extraction of HTML signature in Preferences module + - [web] really delete mailboxes being deleted from the Trash folder (#595, #1189, #641) 2.3.13 (2016-07-06) ------------------- diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index 7b068b863..f7184e72e 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -132,22 +132,23 @@ } - (NSURL *) _trashedURLOfFolder: (NSURL *) srcURL - withCO: (SOGoMailFolder *) co + withObject: (SOGoMailFolder *) co { - NSURL *destURL; NSString *trashFolderName, *folderName, *path, *testPath; NGImap4Connection *connection; - int i = 1; + NSURL *destURL; id test; + int i; connection = [co imap4Connection]; - folderName = [[srcURL path] lastPathComponent]; trashFolderName = [[co mailAccountFolder] trashFolderNameInContext: context]; path = [NSString stringWithFormat: @"/%@/%@", trashFolderName, folderName]; testPath = path; + i = 1; + while ( i < 10 ) { test = [[connection client] select: testPath]; @@ -163,7 +164,7 @@ } } destURL = [[NSURL alloc] initWithScheme: [srcURL scheme] - host: [srcURL host] path: path]; + host: [srcURL host] path: path]; [destURL autorelease]; return destURL; @@ -171,60 +172,76 @@ - (WOResponse *) deleteAction { + NSString *currentMailbox, *currentAccount, *keyForMsgUIDs; + NSMutableDictionary *moduleSettings, *threadsCollapsed; + NGImap4Connection *connection; SOGoMailFolder *co, *inbox; + NSURL *srcURL, *destURL; SOGoUserSettings *us; WOResponse *response; - NGImap4Connection *connection; NSException *error; - NSURL *srcURL, *destURL; - NSMutableDictionary *moduleSettings, *threadsCollapsed; - NSString *currentMailbox, *currentAccount, *keyForMsgUIDs; + + BOOL moved; co = [self clientObject]; - if ([co ensureTrashFolder]) - { - connection = [co imap4Connection]; - srcURL = [co imap4URL]; - destURL = [self _trashedURLOfFolder: srcURL withCO: co]; - connection = [co imap4Connection]; - inbox = [[co mailAccountFolder] inboxFolderInContext: context]; - [[connection client] select: [inbox absoluteImap4Name]]; - error = [connection moveMailboxAtURL: srcURL toURL: destURL]; - if (error) - { - response = [self responseWithStatus: 500]; - [response appendContentString: @"Unable to move folder."]; - } - else - { - // We unsubscribe to the old one, and subscribe back to the new one - [[connection client] subscribe: [destURL path]]; - [[connection client] unsubscribe: [srcURL path]]; - - // Verify if the current folder have any collapsed threads save under it name and erase it - us = [[context activeUser] userSettings]; - moduleSettings = [us objectForKey: @"Mail"]; - threadsCollapsed = [moduleSettings objectForKey:@"threadsCollapsed"]; - currentMailbox = [co nameInContainer]; - currentAccount = [[co container] nameInContainer]; - keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox]; + moved = YES; - if (threadsCollapsed) - { - if ([threadsCollapsed objectForKey:keyForMsgUIDs]) - { - [threadsCollapsed removeObjectForKey:keyForMsgUIDs]; + if ([co ensureTrashFolder]) + { + connection = [co imap4Connection]; + srcURL = [co imap4URL]; + destURL = [self _trashedURLOfFolder: srcURL withObject: co]; + connection = [co imap4Connection]; + inbox = [[co mailAccountFolder] inboxFolderInContext: context]; + [[connection client] select: [inbox absoluteImap4Name]]; + + // If srcURL is a prefix of destURL, that means we are deleting + // the folder within the 'Trash' folder, as it's getting renamed + // over and over with an integer suffix (in trashedURLOfFolder:...) + // If that is the case, we simple delete the folder, instead of renaming it + if ([[destURL path] hasPrefix: [srcURL path]]) + { + error = [connection deleteMailboxAtURL: srcURL]; + moved = NO; + } + else + error = [connection moveMailboxAtURL: srcURL toURL: destURL]; + if (error) + { + response = [self responseWithStatus: 500]; + [response appendContentString: [self labelForKey: @"Unable to move/delete folder." inContext: context]]; + } + else + { + // We unsubscribe to the old one, and subscribe back to the new one + if (moved) + [[connection client] subscribe: [destURL path]]; + [[connection client] unsubscribe: [srcURL path]]; + + // Verify if the current folder have any collapsed threads save under it name and erase it + us = [[context activeUser] userSettings]; + moduleSettings = [us objectForKey: @"Mail"]; + threadsCollapsed = [moduleSettings objectForKey: @"threadsCollapsed"]; + currentMailbox = [co nameInContainer]; + currentAccount = [[co container] nameInContainer]; + keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox]; + + if (threadsCollapsed) + { + if ([threadsCollapsed objectForKey: keyForMsgUIDs]) + { + [threadsCollapsed removeObjectForKey: keyForMsgUIDs]; [us synchronize]; - } - } - response = [self responseWith204]; - } - } + } + } + response = [self responseWith204]; + } + } else - { - response = [self responseWithStatus: 500]; - [response appendContentString: @"Unable to move folder."]; - } + { + response = [self responseWithStatus: 500]; + [response appendContentString: [self labelForKey: @"Unable to move/delete folder." inContext: context]]; + } return response; } @@ -716,7 +733,6 @@ WOResponse *response; WORequest *request; SOGoMailFolder *co; - NSException *error; NSArray *msgUIDs; NSMutableArray *flags; NSString *operation;