From eacb6d9942381216257490456379b0e82e575c53 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 20 Sep 2010 14:36:02 +0000 Subject: [PATCH] See Changelog. Monotone-Parent: 434c3721a8dac924cce0531eebee09d9b27457ea Monotone-Revision: 5004088698623bff1c51c9b3abb0d4085643d720 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2010-09-20T14:36:02 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 18 +++ SoObjects/Mailer/SOGoMailFolder.h | 5 +- SoObjects/Mailer/SOGoMailFolder.m | 111 ++++++++++-------- UI/MailerUI/English.lproj/Localizable.strings | 4 + UI/MailerUI/UIxMailFolderActions.m | 4 +- UI/WebServerResources/MailerUI.js | 17 ++- UI/WebServerResources/generic.js | 8 +- 7 files changed, 112 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96b922248..909104c09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2010-09-20 Francis Lachapelle + + * UI/WebServerResources/MailerUI.js (deleteWithoutTrash): new + function used when the messages can't be copied to the trash + folder (usually because the user's mailbox is overquota). + + * UI/WebServerResources/generic.js (showConfirmDialog): added new + argument variable to overwrite the default callback when user + clicks on the "No" button. + + * SoObjects/Mailer/SOGoMailFolder.m + (-deleteUIDs:useTrashFolder:inContext:): new "useTrashFolder" + argument variable that avoids moving the messages to the trash is + set to YES. + + * UI/MailerUI/UIxMailFolderActions.m (-batchDeleteAction): now + accepts a new form variable, "withoutTrash". + 2010-09-20 Wolfgang Sourdeau * SoObjects/SOGo/LDAPSource.m (-_searchAttributes): added diff --git a/SoObjects/Mailer/SOGoMailFolder.h b/SoObjects/Mailer/SOGoMailFolder.h index 2a4ace0a9..1be729e49 100644 --- a/SoObjects/Mailer/SOGoMailFolder.h +++ b/SoObjects/Mailer/SOGoMailFolder.h @@ -1,4 +1,5 @@ /* + Copyright (C) 2009-2010 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. @@ -48,7 +49,9 @@ - (NSString *) absoluteImap4Name; /* messages */ -- (NSException *) deleteUIDs: (NSArray *) uids inContext: (id) context; +- (NSException *) deleteUIDs: (NSArray *) uids + useTrashFolder: (BOOL) withTrash + inContext: (id) context; - (WOResponse *) archiveUIDs: (NSArray *) uids inArchiveNamed: (NSString *) archiveName inContext: (id) context; diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index e5e14f11d..e34323650 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -1,4 +1,5 @@ /* + Copyright (C) 2009-2010 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG This file is part of OpenGroupware.org. @@ -265,6 +266,7 @@ static NSString *defaultUserID = @"anyone"; /* messages */ - (NSException *) deleteUIDs: (NSArray *) uids + useTrashFolder: (BOOL) withTrash inContext: (id) localContext { SOGoMailFolder *trashFolder; @@ -274,62 +276,75 @@ static NSString *defaultUserID = @"anyone"; NSString *result; BOOL b; - trashFolder = [[self mailAccountFolder] trashFolderInContext: localContext]; - if ([trashFolder isNotNull]) + client = nil; + trashFolder = nil; + b = YES; + if (withTrash) { - if ([trashFolder isKindOfClass: [NSException class]]) - error = (NSException *) trashFolder; + trashFolder = [[self mailAccountFolder] trashFolderInContext: localContext]; + b = NO; + if ([trashFolder isNotNull]) + { + if ([trashFolder isKindOfClass: [NSException class]]) + error = (NSException *) trashFolder; + else + { + client = [[self imap4Connection] client]; + [imap4 selectFolder: [self imap4URL]]; + folderName = [imap4 imap4FolderNameForURL: [trashFolder imap4URL]]; + b = YES; + + // If we are deleting messages within the Trash folder itself, we + // do not, of course, try to move messages to the Trash folder. + if (![folderName isEqualToString: [self relativeImap4Name]]) + { + // 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]) + [[self imap4Connection] createMailbox: folderName + atURL: [[self mailAccountFolder] imap4URL]]; + + result = [[client copyUids: uids toFolder: folderName] + objectForKey: @"result"]; + + b = [result boolValue]; + } + } + } else + error = [NSException exceptionWithHTTPStatus: 500 + reason: @"Did not find Trash folder!"]; + } + + if (b) + { + if (client == nil) { client = [[self imap4Connection] client]; [imap4 selectFolder: [self imap4URL]]; - folderName = [imap4 imap4FolderNameForURL: [trashFolder imap4URL]]; - b = YES; - - // If we are deleting messages within the Trash folder itself, we - // do not, of course, try to move messages to the Trash folder. - if (![folderName isEqualToString: [self relativeImap4Name]]) - { - // 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]) - [[self imap4Connection] createMailbox: folderName - atURL: [[self mailAccountFolder] imap4URL]]; - - result = [[client copyUids: uids toFolder: folderName] - objectForKey: @"result"]; - - b = [result boolValue]; - } - - if (b) - { - result = [[client storeFlags: [NSArray arrayWithObject: @"Deleted"] - forUIDs: uids addOrRemove: YES] - objectForKey: @"result"]; - if ([result boolValue]) - { - [self markForExpunge]; - [trashFolder flushMailCaches]; - error = nil; - } - else - error - = [NSException exceptionWithHTTPStatus:500 - reason: @"Could not mark UIDs as Deleted"]; - } - else - error = [NSException exceptionWithHTTPStatus:500 - reason: @"Could not copy UIDs"]; } + result = [[client storeFlags: [NSArray arrayWithObject: @"Deleted"] + forUIDs: uids addOrRemove: YES] + objectForKey: @"result"]; + if ([result boolValue]) + { + [self markForExpunge]; + if (trashFolder) + [trashFolder flushMailCaches]; + error = nil; + } + else + error + = [NSException exceptionWithHTTPStatus:500 + reason: @"Could not mark UIDs as Deleted"]; } else - error = [NSException exceptionWithHTTPStatus: 500 - reason: @"Did not find Trash folder!"]; - + error = [NSException exceptionWithHTTPStatus:500 + reason: @"Could not copy UIDs"]; + return error; } diff --git a/UI/MailerUI/English.lproj/Localizable.strings b/UI/MailerUI/English.lproj/Localizable.strings index a61c5a16f..25ec20743 100644 --- a/UI/MailerUI/English.lproj/Localizable.strings +++ b/UI/MailerUI/English.lproj/Localizable.strings @@ -272,6 +272,10 @@ "Copying a message into its own folder is impossible!" = "Copying a message into its own folder is impossible!"; +/* Message operations */ +"The messages could not be moved to the trash folder. Would you like to delete them now?" += "The messages could not be moved to the trash folder. Would you like to delete them now?"; + /* Message editing */ "error_validationfailed" = "Validation failed"; "error_missingsubject" = "Subject is missing"; diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index 1d530e236..45a45dd69 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -240,15 +240,17 @@ WOResponse *response; NSArray *uids; NSString *value; + BOOL withoutTrash; co = [self clientObject]; value = [[context request] formValueForKey: @"uid"]; + withoutTrash = [[[context request] formValueForKey: @"withoutTrash"] boolValue]; response = nil; if ([value length] > 0) { uids = [value componentsSeparatedByString: @","]; - response = (WOResponse *) [co deleteUIDs: uids inContext: context]; + response = (WOResponse *) [co deleteUIDs: uids useTrashFolder: !withoutTrash inContext: context]; if (!response) response = [self responseWith204]; } diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index 109a65dc3..971564bb5 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -454,12 +454,27 @@ function deleteSelectedMessagesCallback(http) { if (data["refreshUnseenCount"]) getUnseenCountForFolder(data["mailbox"]); } + else if (!http.callbackData["withoutTrash"]) { + showConfirmDialog(_("Warning"), + _("The messages could not be moved to the trash folder. Would you like to delete them now?"), + deleteMessagesWithoutTrash.bind(document, http.callbackData), + function() { refreshCurrentFolder(); disposeDialog(); }); + } else { - log ("deleteSelectedMessagesCallback: problem during ajax request " + http.status); + log ("deleteSelectedMessagesCallback: problem during ajax request " + http.status + " : " + http.responseText); refreshCurrentFolder(); } } +function deleteMessagesWithoutTrash(data) { + var url = ApplicationBaseURL + encodeURI(data["mailbox"]) + "/batchDelete"; + var parameters = "uid=" + data["id"].join(",") + '&withoutTrash=1'; + data["withoutTrash"] = true; + triggerAjaxRequest(url, deleteSelectedMessagesCallback, data, parameters, + { "Content-type": "application/x-www-form-urlencoded" }); + disposeDialog(); +} + function onMenuDeleteMessage(event) { deleteSelectedMessages(); preventDefault(event); diff --git a/UI/WebServerResources/generic.js b/UI/WebServerResources/generic.js index fec9a604c..d433d1877 100644 --- a/UI/WebServerResources/generic.js +++ b/UI/WebServerResources/generic.js @@ -1758,7 +1758,7 @@ function createDialog(id, title, legend, content, positionClass) { else { bgDiv = createElement("div", "bgDialogDiv", ["bgDialog"]); document.body.appendChild(bgDiv); - bgDiv.observe("click", disposeDialog); + //bgDiv.observe("click", disposeDialog); } } @@ -1822,15 +1822,15 @@ function _showAlertDialog(label) { dialog.show(); } -function showConfirmDialog(title, label, callback) { +function showConfirmDialog(title, label, callbackYes, callbackNo) { var dialog = dialogs[label]; if (dialog) { $("bgDialogDiv").show(); } else { var fields = createElement("p"); - fields.appendChild(createButton(null, _("Yes"), callback)); - fields.appendChild(createButton(null, _("No"), disposeDialog)); + fields.appendChild(createButton(null, _("Yes"), callbackYes)); + fields.appendChild(createButton(null, _("No"), callbackNo || disposeDialog)); dialog = createDialog(null, title, label,