diff --git a/ChangeLog b/ChangeLog index c2cb1a151..e74c803cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,17 @@ 2007-05-28 Wolfgang Sourdeau + * UI/MailerUI/UIxMailFolderActions.m ([UIxMailFolderActions + -emptyTrashAction]): new method inspired by a similar one from + UIxMailListView, to which we added the ability to remove + subfolders. + + * UI/MailerUI/UIxMailListView.m ([-emptyTrashAction]): removed + method. Replaced with a similar one in UIxMailFolderActions. + * UI/MailerUI/UIxMailFolderActions.m ([UIxMailFolderActions -renameFolderAction]): implemented method. + ([UIxMailFolderActions -deleteFolderAction]): no longer delete the + specified folder. Instead, we put it in the trash folder. * UI/MailerUI/UIxMailListView.m ([-createFolderAction]): removed method, replaced with a similar method in the new diff --git a/UI/MailerUI/UIxMailAccountActions.h b/UI/MailerUI/UIxMailAccountActions.h index 36d55657e..e6c84f7d0 100644 --- a/UI/MailerUI/UIxMailAccountActions.h +++ b/UI/MailerUI/UIxMailAccountActions.h @@ -32,8 +32,6 @@ NSString *draftFolderName; NSString *sentFolderName; NSString *trashFolderName; - NSString *sharedFolderName; - NSString *otherUsersFolderName; } - (WOResponse *) listMailboxesAction; diff --git a/UI/MailerUI/UIxMailAccountActions.m b/UI/MailerUI/UIxMailAccountActions.m index b2c8dbbb6..472db88d5 100644 --- a/UI/MailerUI/UIxMailAccountActions.m +++ b/UI/MailerUI/UIxMailAccountActions.m @@ -87,30 +87,17 @@ - (WOResponse *) listMailboxesAction { - SOGoMailAccount *clientObject; - NSArray *rawFolders, *folders, *mainFolders; - NSMutableArray *newFolders; + SOGoMailAccount *co; + NSArray *rawFolders, *folders; WOResponse *response; - clientObject = [self clientObject]; - rawFolders = [[clientObject imap4Connection] - allFoldersForURL: [clientObject imap4URL]]; + co = [self clientObject]; + draftFolderName = [co draftsFolderNameInContext: context]; + sentFolderName = [co sentFolderNameInContext: context]; + trashFolderName = [co trashFolderNameInContext: context]; - draftFolderName = [clientObject draftsFolderNameInContext: context]; - sentFolderName = [clientObject sentFolderNameInContext: context]; - trashFolderName = [clientObject trashFolderNameInContext: context]; - sharedFolderName = [clientObject sharedFolderName]; - otherUsersFolderName = [clientObject otherUsersFolderName]; - mainFolders = [NSArray arrayWithObjects: @"INBOX", draftFolderName, - sentFolderName, trashFolderName, nil]; - - newFolders = [NSMutableArray arrayWithArray: rawFolders]; - [newFolders removeObjectsInArray: mainFolders]; - [newFolders sortUsingSelector: @selector (caseInsensitiveCompare:)]; - [newFolders replaceObjectsInRange: NSMakeRange (0, 0) - withObjectsFromArray: mainFolders]; - - folders = [self _jsonFolders: [newFolders objectEnumerator]]; + rawFolders = [co allFolderPaths]; + folders = [self _jsonFolders: [rawFolders objectEnumerator]]; response = [context response]; [response appendContentString: [folders jsonRepresentation]]; diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index 2045bcfdc..b7fecc530 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -31,6 +31,8 @@ #import #import +#import +#import #import "UIxMailFolderActions.h" @@ -73,18 +75,14 @@ renamedTo: (NSString *) folderName { NSString *path; - NSMutableArray *pathArray; NSURL *destURL; - path = [srcURL path]; - pathArray = [NSMutableArray arrayWithArray: - [path componentsSeparatedByString: @"/"]]; - [pathArray replaceObjectAtIndex: [pathArray count] - 1 - withObject: folderName]; - + path = [[srcURL path] stringByDeletingLastPathComponent]; + destURL = [[NSURL alloc] initWithScheme: [srcURL scheme] host: [srcURL host] - path: [pathArray componentsJoinedByString: @"/"]]; + path: [NSString stringWithFormat: @"%@%@", + path, folderName]]; [destURL autorelease]; return destURL; @@ -127,26 +125,89 @@ return response; } +- (NSURL *) _trashedURLOfFolder: (NSURL *) srcURL + withCO: (SOGoMailFolder *) co +{ + NSURL *destURL; + NSString *trashFolderName, *folderName; + + folderName = [[srcURL path] lastPathComponent]; + trashFolderName + = [[co mailAccountFolder] trashFolderNameInContext: context]; + + destURL = [[NSURL alloc] initWithScheme: [srcURL scheme] + host: [srcURL host] + path: [NSString stringWithFormat: @"/%@/%@", + trashFolderName, folderName]]; + [destURL autorelease]; + + return destURL; +} + - (WOResponse *) deleteFolderAction { SOGoMailFolder *co; WOResponse *response; NGImap4Connection *connection; NSException *error; + NSURL *srcURL, *destURL; co = [self clientObject]; response = [context response]; connection = [co imap4Connection]; - error = [connection deleteMailboxAtURL: [co imap4URL]]; + srcURL = [co imap4URL]; + destURL = [self _trashedURLOfFolder: srcURL + withCO: co]; + connection = [co imap4Connection]; + error = [connection moveMailboxAtURL: srcURL + toURL: destURL]; if (error) { [response setStatus: 403]; - [response appendContentString: @"Unable to delete folder."]; + [response appendContentString: @"Unable to move folder."]; } else [response setStatus: 204]; - return response; + return response; +} + +- (WOResponse *) emptyTrashAction +{ + NSException *error; + SOGoTrashFolder *co; + NSEnumerator *subfolders; + WOResponse *response; + NGImap4Connection *connection; + NSURL *currentURL; + + co = [self clientObject]; + response = [context response]; + + error = [co addFlagsToAllMessages: @"deleted"]; + if (!error) + error = [co expunge]; + if (!error) + { + [co flushMailCaches]; + connection = [co imap4Connection]; + subfolders = [[co subfoldersURL] objectEnumerator]; + currentURL = [subfolders nextObject]; + while (currentURL) + { + [connection deleteMailboxAtURL: currentURL]; + currentURL = [subfolders nextObject]; + } + } + if (error) + { + [response setStatus: 403]; + [response appendContentString: @"Unable to empty the trash folder."]; + } + else + [response setStatus: 204]; + + return response; } @end diff --git a/UI/MailerUI/UIxMailListView.m b/UI/MailerUI/UIxMailListView.m index f9eb19a21..de669d916 100644 --- a/UI/MailerUI/UIxMailListView.m +++ b/UI/MailerUI/UIxMailListView.m @@ -539,46 +539,6 @@ static int attachmentFlagSize = 8096; return [self redirectToLocation:@"view"]; } -- (id) emptyTrashAction -{ - // TODO: we might want to flush the caches? - NSException *error; - id client; - - if ((client = [self clientObject]) == nil) { - error = [NSException exceptionWithHTTPStatus:404 /* Not Found */ - reason:@"did not find mail folder"]; - return [self redirectToViewWithError:error]; - } - - if (![client isKindOfClass:NSClassFromString(@"SOGoTrashFolder")]) { - /* would be better to move the method to an own class, but well .. */ - error = [NSException exceptionWithHTTPStatus:400 /* Bad Request */ - reason:@"method cannot be invoked on " - @"the specified object"]; - return [self redirectToViewWithError:error]; - } - - /* mark all as deleted */ - - [self logWithFormat:@"TODO: must mark all as deleted for empty-trash"]; - - error = [[self clientObject] addFlagsToAllMessages:@"deleted"]; - if (error != nil) - // TODO: improve error - return [self redirectToViewWithError:error]; - - /* expunge */ - - if ((error = [[self clientObject] expunge]) != nil) - // TODO: improve error - return [self redirectToViewWithError:error]; - - if ([client respondsToSelector:@selector(flushMailCaches)]) - [client flushMailCaches]; - return [self redirectToLocation:@"view"]; -} - @end /* UIxMailListView */ diff --git a/UI/MailerUI/product.plist b/UI/MailerUI/product.plist index 7adcfbca2..6842f50d4 100644 --- a/UI/MailerUI/product.plist +++ b/UI/MailerUI/product.plist @@ -164,8 +164,8 @@ methods = { emptyTrash = { protectedBy = "View"; - pageName = "UIxMailListView"; - actionName = "emptyTrash"; + actionClass = "UIxMailFolderActions"; + actionName = "emptyTrash"; }; }; }; diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index af3881e8f..2c40d3404 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -1261,6 +1261,12 @@ function onMenuDeleteFolder(event) { } } +function onMenuEmptyTrash(event) { + var folderID = document.menuTarget.getAttribute("dataname"); + var urlstr = URLForFolderID(folderID) + "/emptyTrash"; + triggerAjaxRequest(urlstr, folderOperationCallback); +} + function folderOperationCallback(http) { if (http.readyState == 4 && http.status == 204) @@ -1282,7 +1288,8 @@ function initializeMenus() { onMenuSharing); menus["trashIconMenu"] = new Array(null, null, null, "-", null, onMenuCreateFolder, null, - null, "-", null, onMenuSharing); + onMenuEmptyTrash, "-", null, + onMenuSharing); menus["mailboxIconMenu"] = new Array(null, null, null, "-", null, onMenuCreateFolder, onMenuRenameFolder,