Skip to content

Commit

Permalink
fix(mail): handle folders that end with a question mark
Browse files Browse the repository at this point in the history
We now avoid using NSURL.

Fixes #5303
  • Loading branch information
cgx committed May 18, 2021
1 parent d0056d3 commit 657f00f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 45 deletions.
21 changes: 7 additions & 14 deletions SoObjects/Mailer/SOGoMailFolder.m
Expand Up @@ -301,8 +301,7 @@ - (NSException *) renameTo: (NSString *) theNewName
{
NSException *error;
SOGoMailFolder *inbox;
NSURL *destURL;
NSString *path, *newName;
NSString *path, *newName, *destName;
NGImap4Client *client;

if ([theNewName length] > 0)
Expand All @@ -324,22 +323,16 @@ - (NSException *) renameTo: (NSString *) theNewName

// If new name contains the path - dont't need to add
if ([newName rangeOfString: @"/"].location == NSNotFound)
destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme]
host: [imap4URL host]
path: [NSString stringWithFormat: @"%@%@",
path, newName]];
destName = [NSString stringWithFormat: @"%@%@",
path, newName];
else
destURL = [[NSURL alloc] initWithScheme: [imap4URL scheme]
host: [imap4URL host]
path: [NSString stringWithFormat: @"%@",
newName]];
[destURL autorelease];
error = [imap4 moveMailboxAtURL: imap4URL
toURL: destURL];
destName = newName;
error = [imap4 moveMailbox: [imap4URL path]
to: destName];
if (!error)
{
// We unsubscribe to the old one, and subscribe back to the new one
[client subscribe: [destURL path]];
[client subscribe: destName];
[client unsubscribe: [imap4URL path]];

ASSIGN (imap4URL, nil);
Expand Down
57 changes: 27 additions & 30 deletions UI/MailerUI/UIxMailFolderActions.m
Expand Up @@ -287,12 +287,11 @@ - (WOResponse *) moveFolderAction
return response;
}

- (NSURL *) _trashedURLOfFolder: (NSURL *) srcURL
withObject: (SOGoMailFolder *) co
- (NSString *) _trashedNameOfFolder: (NSURL *) srcURL
withObject: (SOGoMailFolder *) co
{
NSString *trashFolderName, *folderName, *path, *testPath;
NGImap4Connection *connection;
NSURL *destURL;
id test;
int i;

Expand All @@ -318,14 +317,11 @@ - (NSURL *) _trashedURLOfFolder: (NSURL *) srcURL
break;
}
}
destURL = [[NSURL alloc] initWithScheme: [srcURL scheme]
host: [srcURL host] path: path];
[destURL autorelease];

return destURL;
return path;
}

- (void) _removeFolderAtURL: (NSURL *) srcURL
- (void) _removeFolder: (NSString *) srcName
{
NGImap4Connection *connection;
NSMutableDictionary *moduleSettings, *threadsCollapsed;;
Expand All @@ -337,7 +333,7 @@ - (void) _removeFolderAtURL: (NSURL *) srcURL
connection = [co imap4Connection];

// Unsubscribe from mailbox
[[connection client] unsubscribe: [srcURL path]];
[[connection client] unsubscribe: srcName];

// Verify if the current folder have any collapsed threads save under it name and erase it
us = [[context activeUser] userSettings];
Expand All @@ -359,21 +355,22 @@ - (void) _removeFolderAtURL: (NSURL *) srcURL
- (WOResponse *) deleteAction
{
NSDictionary *jsonRequest, *jsonResponse;
NSEnumerator *subURLs;
NSEnumerator *subNames;
NGImap4Connection *connection;
SOGoMailFolder *co, *inbox;
NSURL *srcURL, *destURL, *currentURL;
NSURL *srcURL;
WORequest *request;
WOResponse *response;
NSException *error;
NSInteger count;
NSString *destName, *currentName;
BOOL moved, withTrash;

request = [context request];
co = [self clientObject];
connection = [co imap4Connection];
srcURL = [co imap4URL];
subURLs = [[co allFolderURLs] objectEnumerator];
subNames = [[co allFolderPaths] objectEnumerator];
jsonRequest = [[request contentAsString] objectFromJSONString];
withTrash = ![[jsonRequest objectForKey: @"withoutTrash"] boolValue];
error = nil;
Expand All @@ -383,22 +380,22 @@ - (WOResponse *) deleteAction
{
if ([co ensureTrashFolder])
{
destURL = [self _trashedURLOfFolder: srcURL withObject: co];
destName = [self _trashedNameOfFolder: 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]])
if ([destName hasPrefix: [srcURL path]])
{
error = [connection deleteMailboxAtURL: srcURL];
moved = NO;
}
else
{
error = [connection moveMailboxAtURL: srcURL toURL: destURL];
error = [connection moveMailbox: [srcURL path] to: destName];
}
if (error)
{
Expand All @@ -409,25 +406,25 @@ - (WOResponse *) deleteAction
else
{
// We unsubscribe to the old one, and subscribe back to the new one
[self _removeFolderAtURL: srcURL];
[self _removeFolder: [srcURL path]];
if (moved)
[[connection client] subscribe: [destURL path]];
[[connection client] subscribe: destName];

// We do the same for all subfolders
count = [[srcURL pathComponents] count];
while (!error && (currentURL = [subURLs nextObject]))
while (!error && (currentName = [subNames nextObject]))
{
[self _removeFolderAtURL: currentURL];
[self _removeFolder: currentName];
if (moved)
{
NSArray *currentComponents;
NSMutableArray *destComponents;
NSInteger currentCount;

destComponents = [NSMutableArray arrayWithArray: [destURL pathComponents]];
destComponents = [NSMutableArray arrayWithArray: [destName componentsSeparatedByString: @"/"]];
[destComponents removeObjectAtIndex: 0]; // remove leading forward slash
currentCount = [[currentURL pathComponents] count];
currentComponents = [[currentURL pathComponents] subarrayWithRange: NSMakeRange(count, currentCount - count)];
currentCount = [[currentName componentsSeparatedByString: @"/"] count];
currentComponents = [[currentName componentsSeparatedByString: @"/"] subarrayWithRange: NSMakeRange(count, currentCount - count)];
[destComponents addObjectsFromArray: currentComponents];

[[connection client] subscribe: [NSString stringWithFormat: @"/%@", [destComponents componentsJoinedByString: @"/"]]];
Expand Down Expand Up @@ -457,10 +454,10 @@ - (WOResponse *) deleteAction
else
{
// Cleanup all references to mailbox and submailboxes
[self _removeFolderAtURL: srcURL];
while (!error && (currentURL = [subURLs nextObject]))
[self _removeFolder: [srcURL path]];
while (!error && (currentName = [subNames nextObject]))
{
[self _removeFolderAtURL: currentURL];
[self _removeFolder: currentName];
}
response = [self responseWith204];
}
Expand Down Expand Up @@ -884,7 +881,7 @@ - (WOResponse *) emptyTrashAction
NSEnumerator *subfolders;
WOResponse *response;
NGImap4Connection *connection;
NSURL *currentURL;
NSString *currentName;
NSDictionary *data;

id quota;
Expand All @@ -900,11 +897,11 @@ - (WOResponse *) emptyTrashAction

// Delete folders within the trash
connection = [co imap4Connection];
subfolders = [[co allFolderURLs] objectEnumerator];
while ((currentURL = [subfolders nextObject]))
subfolders = [[co allFolderPaths] objectEnumerator];
while ((currentName = [subfolders nextObject]))
{
[[connection client] unsubscribe: [currentURL path]];
[connection deleteMailboxAtURL: currentURL];
[[connection client] unsubscribe: currentName];
[connection deleteMailbox: currentName];
}
}
if (error)
Expand Down
Expand Up @@ -273,11 +273,13 @@
};

this.share = function() {
var encodeURL = angular.bind(this.folder.constructor.$$resource,
this.folder.constructor.$$resource.encodeURL);
// Fetch list of ACL users
this.folder.$acl.$users().then(function() {
// Show ACL editor
$mdDialog.show({
templateUrl: $menuCtrl.folder.id + '/UIxAclEditor', // UI/Templates/UIxAclEditor.wox
templateUrl: encodeURL($menuCtrl.folder.id).join('/') + '/UIxAclEditor', // UI/Templates/UIxAclEditor.wox
controller: 'AclController', // from the ng module SOGo.Common
controllerAs: 'acl',
clickOutsideToClose: true,
Expand Down

0 comments on commit 657f00f

Please sign in to comment.