Monotone-Parent: 9bec05d8cd20a1e980c6381c10c71a9e57b984e6

Monotone-Revision: 4012894fc79b7641cebac42647c13996d86e9eca

Monotone-Author: wsourdeau@inverse.ca
Monotone-Date: 2012-01-30T20:47:07
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
Wolfgang Sourdeau
2012-01-30 20:47:07 +00:00
parent 98c9f995c8
commit 3bb6a1b975
3 changed files with 55 additions and 54 deletions

View File

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

View File

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

View File

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