From 3bb6a1b975c8a1ca12ac26be0e5604198db21cb7 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Mon, 30 Jan 2012 20:47:07 +0000 Subject: [PATCH] Monotone-Parent: 9bec05d8cd20a1e980c6381c10c71a9e57b984e6 Monotone-Revision: 4012894fc79b7641cebac42647c13996d86e9eca Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-01-30T20:47:07 Monotone-Branch: ca.inverse.sogo --- SoObjects/Mailer/SOGoMailFolder.h | 4 +-- SoObjects/Mailer/SOGoMailFolder.m | 47 ++++++++++++++++++++++++ UI/MailerUI/UIxMailFolderActions.m | 58 ++++-------------------------- 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/SoObjects/Mailer/SOGoMailFolder.h b/SoObjects/Mailer/SOGoMailFolder.h index bd23afbeb..f1a9e15cd 100644 --- a/SoObjects/Mailer/SOGoMailFolder.h +++ b/SoObjects/Mailer/SOGoMailFolder.h @@ -86,6 +86,8 @@ - (NSException *) expunge; +- (NSException *) renameTo: (NSString *) newName; + - (NSCalendarDate *) mostRecentMessageDate; /* flags */ @@ -94,8 +96,6 @@ /* folder type */ -- (NSString *) outlookFolderClass; - - (NSArray *) subfolders; - (BOOL) isSpecialFolder; diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index fbcc73f7e..03e7b9b15 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -267,6 +267,53 @@ static NSString *defaultUserID = @"anyone"; return filenames; } +- (NSException *) renameTo: (NSString *) newName +{ + NSException *error; + SOGoMailFolder *inbox; + NSURL *destURL; + NSString *path; + NGImap4Client *client; + + if ([newName length] > 0) + { + [self imap4URL]; + + [self imap4Connection]; + client = [imap4 client]; + + inbox = [[self mailAccountFolder] inboxFolderInContext: context]; + [client select: [inbox absoluteImap4Name]]; + + path = [[imap4URL path] stringByDeletingLastPathComponent]; + if (![path hasSuffix: @"/"]) + path = [path stringByAppendingString: @"/"]; + destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme] + host: [imap4URL host] + path: [NSString stringWithFormat: @"%@%@", + path, newName]]; + [destURL autorelease]; + error = [imap4 moveMailboxAtURL: imap4URL + toURL: destURL]; + if (!error) + { + // We unsubscribe to the old one, and subscribe back to the new one + if ([[[context activeUser] userDefaults] + mailShowSubscribedFoldersOnly]) + { + [client subscribe: [destURL path]]; + [client unsubscribe: [imap4URL path]]; + } + } + } + else + error = [NSException exceptionWithName: @"SOGoMailException" + reason: @"given name is empty" + userInfo: nil]; + + return error; +} + /* messages */ - (void) prefetchCoreInfosForMessageKeys: (NSArray *) keys { diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m index 57f94973e..2dc1371ba 100644 --- a/UI/MailerUI/UIxMailFolderActions.m +++ b/UI/MailerUI/UIxMailFolderActions.m @@ -84,70 +84,24 @@ return response; } -- (NSURL *) _urlOfFolder: (NSURL *) srcURL - renamedTo: (NSString *) folderName -{ - NSString *path; - NSURL *destURL; - - path = [[srcURL path] stringByDeletingLastPathComponent]; - if (![path hasSuffix: @"/"]) - path = [path stringByAppendingString: @"/"]; - - destURL = [[NSURL alloc] initWithScheme: [srcURL scheme] - host: [srcURL host] - path: [NSString stringWithFormat: @"%@%@", - path, folderName]]; - [destURL autorelease]; - - return destURL; -} - - (WOResponse *) renameFolderAction { - SOGoMailFolder *co, *inbox; + SOGoMailFolder *co; WOResponse *response; - NGImap4Connection *connection; NSException *error; NSString *folderName; - NSURL *srcURL, *destURL; co = [self clientObject]; folderName = [[context request] formValueForKey: @"name"]; - if ([folderName length] > 0) - { - srcURL = [co imap4URL]; - destURL = [self _urlOfFolder: srcURL renamedTo: folderName]; - 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 rename folder."]; - } - else - { - // We unsubscribe to the old one, and subscribe back to the new one - if ([[[context activeUser] userDefaults] - mailShowSubscribedFoldersOnly]) - { - [[connection client] subscribe: [destURL path]]; - [[connection client] unsubscribe: [srcURL path]]; - } - - response = [self responseWith204]; - } - } - else + error = [co renameTo: folderName]; + if (error) { response = [self responseWithStatus: 500]; - [response appendContentString: @"Missing 'name' parameter."]; + [response appendContentString: @"Unable to rename folder."]; } + else + response = [self responseWith204]; return response; }