mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-15 05:14:53 +00:00
@@ -170,42 +170,99 @@
|
||||
return destURL;
|
||||
}
|
||||
|
||||
- (void) _removeFolder
|
||||
{
|
||||
NGImap4Connection *connection;
|
||||
NSMutableDictionary *moduleSettings, *threadsCollapsed;;
|
||||
NSString *keyForMsgUIDs, *currentMailbox, *currentAccount;
|
||||
NSURL *srcURL;
|
||||
SOGoMailFolder *co;
|
||||
SOGoUserSettings *us;
|
||||
|
||||
co = [self clientObject];
|
||||
srcURL = [co imap4URL];
|
||||
connection = [co imap4Connection];
|
||||
|
||||
// Unsubscribe from mailbox
|
||||
[[connection client] unsubscribe: [srcURL path]];
|
||||
|
||||
// Verify if the current folder have any collapsed threads save under it name and erase it
|
||||
us = [[context activeUser] userSettings];
|
||||
moduleSettings = [us objectForKey: @"Mail"];
|
||||
threadsCollapsed = [moduleSettings objectForKey: @"threadsCollapsed"];
|
||||
if (threadsCollapsed)
|
||||
{
|
||||
currentMailbox = [co nameInContainer];
|
||||
currentAccount = [[co container] nameInContainer];
|
||||
keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox];
|
||||
if ([threadsCollapsed objectForKey: keyForMsgUIDs])
|
||||
{
|
||||
[threadsCollapsed removeObjectForKey: keyForMsgUIDs];
|
||||
[us synchronize];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (WOResponse *) deleteAction
|
||||
{
|
||||
NSString *currentMailbox, *currentAccount, *keyForMsgUIDs;
|
||||
NSMutableDictionary *moduleSettings, *threadsCollapsed;
|
||||
NGImap4Connection *connection;
|
||||
SOGoMailFolder *co, *inbox;
|
||||
NSURL *srcURL, *destURL;
|
||||
SOGoUserSettings *us;
|
||||
WOResponse *response;
|
||||
NSException *error;
|
||||
|
||||
BOOL moved;
|
||||
BOOL moved, withTrash;
|
||||
|
||||
co = [self clientObject];
|
||||
srcURL = [co imap4URL];
|
||||
withTrash = ![[[context request] formValueForKey: @"withoutTrash"] boolValue];
|
||||
moved = YES;
|
||||
|
||||
if ([co ensureTrashFolder])
|
||||
if (withTrash)
|
||||
{
|
||||
connection = [co imap4Connection];
|
||||
srcURL = [co imap4URL];
|
||||
destURL = [self _trashedURLOfFolder: srcURL withObject: co];
|
||||
connection = [co imap4Connection];
|
||||
inbox = [[co mailAccountFolder] inboxFolderInContext: context];
|
||||
[[connection client] select: [inbox absoluteImap4Name]];
|
||||
|
||||
// If srcURL is a prefix of destURL, that means we are deleting
|
||||
// the folder within the 'Trash' folder, as it's getting renamed
|
||||
// over and over with an integer suffix (in trashedURLOfFolder:...)
|
||||
// If that is the case, we simple delete the folder, instead of renaming it
|
||||
if ([[destURL path] hasPrefix: [srcURL path]])
|
||||
if ([co ensureTrashFolder])
|
||||
{
|
||||
error = [connection deleteMailboxAtURL: srcURL];
|
||||
moved = NO;
|
||||
connection = [co imap4Connection];
|
||||
destURL = [self _trashedURLOfFolder: srcURL withObject: co];
|
||||
inbox = [[co mailAccountFolder] inboxFolderInContext: context];
|
||||
[[connection client] select: [inbox absoluteImap4Name]];
|
||||
|
||||
// If srcURL is a prefix of destURL, that means we are deleting
|
||||
// the folder within the 'Trash' folder, as it's getting renamed
|
||||
// over and over with an integer suffix (in trashedURLOfFolder:...)
|
||||
// If that is the case, we simple delete the folder, instead of renaming it
|
||||
if ([[destURL path] hasPrefix: [srcURL path]])
|
||||
{
|
||||
error = [connection deleteMailboxAtURL: srcURL];
|
||||
moved = NO;
|
||||
}
|
||||
else
|
||||
error = [connection moveMailboxAtURL: srcURL toURL: destURL];
|
||||
if (error)
|
||||
{
|
||||
response = [self responseWithStatus: 500];
|
||||
[response appendContentString: [self labelForKey: @"Unable to move/delete folder." inContext: context]];
|
||||
}
|
||||
else
|
||||
{
|
||||
// We unsubscribe to the old one, and subscribe back to the new one
|
||||
if (moved)
|
||||
[[connection client] subscribe: [destURL path]];
|
||||
[self _removeFolder];
|
||||
response = [self responseWith204];
|
||||
}
|
||||
}
|
||||
else
|
||||
error = [connection moveMailboxAtURL: srcURL toURL: destURL];
|
||||
{
|
||||
response = [self responseWithStatus: 500];
|
||||
[response appendContentString: [self labelForKey: @"Unable to move/delete folder." inContext: context]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Immediately delete mailbox
|
||||
connection = [co imap4Connection];
|
||||
error = [connection deleteMailboxAtURL: srcURL];
|
||||
if (error)
|
||||
{
|
||||
response = [self responseWithStatus: 500];
|
||||
@@ -213,35 +270,10 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
// We unsubscribe to the old one, and subscribe back to the new one
|
||||
if (moved)
|
||||
[[connection client] subscribe: [destURL path]];
|
||||
[[connection client] unsubscribe: [srcURL path]];
|
||||
|
||||
// Verify if the current folder have any collapsed threads save under it name and erase it
|
||||
us = [[context activeUser] userSettings];
|
||||
moduleSettings = [us objectForKey: @"Mail"];
|
||||
threadsCollapsed = [moduleSettings objectForKey: @"threadsCollapsed"];
|
||||
currentMailbox = [co nameInContainer];
|
||||
currentAccount = [[co container] nameInContainer];
|
||||
keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox];
|
||||
|
||||
if (threadsCollapsed)
|
||||
{
|
||||
if ([threadsCollapsed objectForKey: keyForMsgUIDs])
|
||||
{
|
||||
[threadsCollapsed removeObjectForKey: keyForMsgUIDs];
|
||||
[us synchronize];
|
||||
}
|
||||
}
|
||||
[self _removeFolder];
|
||||
response = [self responseWith204];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response = [self responseWithStatus: 500];
|
||||
[response appendContentString: [self labelForKey: @"Unable to move/delete folder." inContext: context]];
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user