From dfe369dd207d0aba4792c70b5fdb22f54440efab Mon Sep 17 00:00:00 2001 From: Luc Charland Date: Tue, 25 Sep 2012 10:29:24 -0400 Subject: [PATCH] Fixed bug #1944 Deleting a mail folder doesn't create the Trash mailbox. --- SoObjects/Mailer/SOGoMailFolder.h | 2 ++ SoObjects/Mailer/SOGoMailFolder.m | 34 ++++++++++++++++------ UI/MailerUI/UIxMailFolderActions.m | 46 ++++++++++++++++++------------ 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/SoObjects/Mailer/SOGoMailFolder.h b/SoObjects/Mailer/SOGoMailFolder.h index 98bc94c85..f80702ce5 100644 --- a/SoObjects/Mailer/SOGoMailFolder.h +++ b/SoObjects/Mailer/SOGoMailFolder.h @@ -86,6 +86,8 @@ - (BOOL) create; +- (BOOL) ensureTrashFolder; + - (NSException *) expunge; - (NSException *) renameTo: (NSString *) newName; diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 5e6348bde..bac7e1cf9 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -414,17 +414,15 @@ static NSString *defaultUserID = @"anyone"; { // 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"]; + b = [self ensureTrashFolder]; - if (![result boolValue]) - [imap4 createMailbox: folderName - atURL: [[self mailAccountFolder] imap4URL]]; + if (b) + { + result = [[client copyUids: uids toFolder: folderName] + objectForKey: @"result"]; - result = [[client copyUids: uids toFolder: folderName] - objectForKey: @"result"]; - - b = [result boolValue]; + b = [result boolValue]; + } } } else @@ -956,6 +954,24 @@ static NSString *defaultUserID = @"anyone"; return rc; } +- (BOOL) ensureTrashFolder +{ + SOGoMailFolder *trashFolder; + BOOL rc; + + trashFolder = [[self mailAccountFolder] trashFolderInContext: context]; + rc = NO; + if (![trashFolder isKindOfClass: [NSException class]]) + { + rc = [trashFolder exists]; + if (!rc) + rc = [trashFolder create]; + } + if (!rc) + [self errorWithFormat: @"Cannot create Trash Mailbox"]; + return rc; +} + - (NSException *) delete { NSException *error; diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index 3f3edfc78..729c24b5a 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -153,26 +153,34 @@ NSURL *srcURL, *destURL; co = [self clientObject]; - 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."]; - } + 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]]; + + response = [self responseWith204]; + } + } else - { - // We unsubscribe to the old one, and subscribe back to the new one - [[connection client] subscribe: [destURL path]]; - [[connection client] unsubscribe: [srcURL path]]; - - response = [self responseWith204]; - } + { + response = [self responseWithStatus: 500]; + [response appendContentString: @"Unable to move folder."]; + } return response; }