Monotone-Parent: 351c343491eb5005eeec456fd7caf97dd6c27489

Monotone-Revision: f445ddae9e72252fda8d9a7adee3c89ef2f81c87

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2007-05-28T19:05:00
Monotone-Branch: ca.inverse.sogo
maint-2.0.2
Wolfgang Sourdeau 2007-05-28 19:05:00 +00:00
parent 85d84068ac
commit 52c2283eba
7 changed files with 100 additions and 77 deletions

View File

@ -1,7 +1,17 @@
2007-05-28 Wolfgang Sourdeau <wsourdeau@inverse.ca>
* 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

View File

@ -32,8 +32,6 @@
NSString *draftFolderName;
NSString *sentFolderName;
NSString *trashFolderName;
NSString *sharedFolderName;
NSString *otherUsersFolderName;
}
- (WOResponse *) listMailboxesAction;

View File

@ -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]];

View File

@ -31,6 +31,8 @@
#import <NGImap4/NGImap4Connection.h>
#import <SoObjects/Mailer/SOGoMailFolder.h>
#import <SoObjects/Mailer/SOGoTrashFolder.h>
#import <SoObjects/Mailer/SOGoMailAccount.h>
#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

View File

@ -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 */

View File

@ -164,8 +164,8 @@
methods = {
emptyTrash = {
protectedBy = "View";
pageName = "UIxMailListView";
actionName = "emptyTrash";
actionClass = "UIxMailFolderActions";
actionName = "emptyTrash";
};
};
};

View File

@ -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,