Improved handling of non-existant vs. subscribed folders over EAS

pull/69/merge
Ludovic Marcotte 2014-12-29 12:43:20 -05:00
parent 204a62aa6a
commit a0c1ce8f3b
3 changed files with 39 additions and 28 deletions

View File

@ -793,10 +793,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{ {
cKey = [allKeys objectAtIndex: i]; cKey = [allKeys objectAtIndex: i];
// ignore invalid folder in cache caused by fs code bugs
if ([cKey isEqualToString:@"(null)"])
continue;
// if a cache entry is not found in imapGUIDs its either an imap which has been deleted or its an other folder type which can be checked via lookupName. // if a cache entry is not found in imapGUIDs its either an imap which has been deleted or its an other folder type which can be checked via lookupName.
if (![imapGUIDs allKeysForObject: cKey]) if (![imapGUIDs allKeysForObject: cKey])
{ {
@ -807,7 +803,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[o setTableUrl: [self folderTableURL]]; [o setTableUrl: [self folderTableURL]];
[o reloadIfNeeded]; [o reloadIfNeeded];
if ([cKey hasPrefix: @"folder"]) if ([cKey hasPrefix: @"folder"] || [cKey isEqualToString:@"(null)"])
{ {
[commands appendFormat: @"<Delete><ServerId>%@</ServerId></Delete>", [[NSString stringWithFormat: @"mail/%@", [cKey substringFromIndex: 6]] stringByEscapingURL]] ; [commands appendFormat: @"<Delete><ServerId>%@</ServerId></Delete>", [[NSString stringWithFormat: @"mail/%@", [cKey substringFromIndex: 6]] stringByEscapingURL]] ;
command_count++; command_count++;
@ -849,6 +845,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
folderMetadata = [allFoldersMetadata objectAtIndex: i]; folderMetadata = [allFoldersMetadata objectAtIndex: i];
nameInCache = [NSString stringWithFormat: @"folder%@", [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]]; nameInCache = [NSString stringWithFormat: @"folder%@", [[folderMetadata objectForKey: @"path"] substringFromIndex: 1]];
// we have no guid - ignore the folder
if (![imapGUIDs objectForKey: nameInCache])
continue;
serverId = [NSString stringWithFormat: @"mail/%@", [[imapGUIDs objectForKey: nameInCache] substringFromIndex: 6]]; serverId = [NSString stringWithFormat: @"mail/%@", [[imapGUIDs objectForKey: nameInCache] substringFromIndex: 6]];
name = [folderMetadata objectForKey: @"displayName"]; name = [folderMetadata objectForKey: @"displayName"];

View File

@ -40,6 +40,7 @@
#import <NGImap4/NGImap4Connection.h> #import <NGImap4/NGImap4Connection.h>
#import <NGImap4/NGImap4Client.h> #import <NGImap4/NGImap4Client.h>
#import <NGImap4/NGImap4Context.h> #import <NGImap4/NGImap4Context.h>
#import <NGImap4/NSString+Imap4.h>
#import <SOGo/NSArray+Utilities.h> #import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSString+Utilities.h> #import <SOGo/NSString+Utilities.h>
@ -667,19 +668,14 @@ static NSString *inboxFolderName = @"INBOX";
NSDictionary *result, *nresult, *namespaceDict; NSDictionary *result, *nresult, *namespaceDict;
NSMutableDictionary *folders; NSMutableDictionary *folders;
NGImap4Client *client; NGImap4Client *client;
SOGoUserDefaults *ud;
NSArray *folderList; NSArray *folderList;
NSEnumerator *e; NSEnumerator *e;
NSString *guid; NSString *guid;
id object; id object;
BOOL subscribedOnly, hasAnnotatemore; BOOL hasAnnotatemore;
ud = [[context activeUser] userDefaults]; folderList = [self allFolderPaths];
subscribedOnly = [ud mailShowSubscribedFoldersOnly];
folderList = [[self imap4Connection] allFoldersForURL: [self imap4URL]
onlySubscribedFolders: subscribedOnly];
folders = [NSMutableDictionary dictionary]; folders = [NSMutableDictionary dictionary];
@ -688,19 +684,19 @@ static NSString *inboxFolderName = @"INBOX";
hasAnnotatemore = [self hasCapability: @"annotatemore"]; hasAnnotatemore = [self hasCapability: @"annotatemore"];
if (hasAnnotatemore) if (hasAnnotatemore)
result = [client annotation: @"*" entryName: @"/comment" attributeName: @"value.priv"]; result = [client annotation: @"*" entryName: @"/comment" attributeName: @"value.priv"];
else else
result = [client lstatus: @"*" flags: [NSArray arrayWithObjects: @"x-guid", nil]]; result = [client lstatus: @"*" flags: [NSArray arrayWithObjects: @"x-guid", nil]];
e = [folderList objectEnumerator]; e = [folderList objectEnumerator];
while ((object = [e nextObject])) while ((object = [e nextObject]))
{ {
if (hasAnnotatemore) if (hasAnnotatemore)
guid = [[[[result objectForKey: @"FolderList"] objectForKey: [object substringFromIndex: 1]] objectForKey: @"/comment"] objectForKey: @"value.priv"]; guid = [[[[result objectForKey: @"FolderList"] objectForKey: [object substringFromIndex: 1]] objectForKey: @"/comment"] objectForKey: @"value.priv"];
else else
guid = [[[result objectForKey: @"status"] objectForKey: [object substringFromIndex: 1]] objectForKey: @"x-guid"]; guid = [[[result objectForKey: @"status"] objectForKey: [object substringFromIndex: 1]] objectForKey: @"x-guid"];
if (!guid) if (!guid)
{ {
// Don't generate a GUID for "Other users" and "Shared" namespace folders - user foldername instead // Don't generate a GUID for "Other users" and "Shared" namespace folders - user foldername instead
@ -710,18 +706,28 @@ static NSString *inboxFolderName = @"INBOX";
[folders setObject: [NSString stringWithFormat: @"folder%@", [object substringFromIndex: 1]] forKey: [NSString stringWithFormat: @"folder%@", [object substringFromIndex: 1]]]; [folders setObject: [NSString stringWithFormat: @"folder%@", [object substringFromIndex: 1]] forKey: [NSString stringWithFormat: @"folder%@", [object substringFromIndex: 1]]];
continue; continue;
} }
guid = [[NSProcessInfo processInfo] globallyUniqueString];
nresult = [client annotation: [object substringFromIndex: 1] entryName: @"/comment" attributeName: @"value.priv" attributeValue: guid];
if (![[nresult objectForKey: @"result"] boolValue]) // if folder doesn't exists - ignore it
guid = [NSString stringWithFormat: @"%@", [object substringFromIndex: 1]]; nresult = [client status: [object substringFromIndex: 1]
flags: [NSArray arrayWithObject: @"UIDVALIDITY"]];
if (![[nresult valueForKey: @"result"] boolValue])
continue;
if (hasAnnotatemore)
{
guid = [[NSProcessInfo processInfo] globallyUniqueString];
nresult = [client annotation: [object substringFromIndex: 1] entryName: @"/comment" attributeName: @"value.priv" attributeValue: guid];
}
// setannotation failed or annotatemore is not available
if (![[nresult objectForKey: @"result"] boolValue] || !hasAnnotatemore)
guid = [NSString stringWithFormat: @"%@", [object substringFromIndex: 1]];
} }
[folders setObject: [NSString stringWithFormat: @"folder%@", guid] forKey: [NSString stringWithFormat: @"folder%@", [object substringFromIndex: 1]]]; [folders setObject: [NSString stringWithFormat: @"folder%@", guid] forKey: [NSString stringWithFormat: @"folder%@", [object substringFromIndex: 1]]];
} }
return folders; return folders;
} }

View File

@ -1069,7 +1069,11 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
NSException *error; NSException *error;
if ([self imap4Connection]) if ([self imap4Connection])
error = [imap4 deleteMailboxAtURL: [self imap4URL]]; {
error = [imap4 deleteMailboxAtURL: [self imap4URL]];
if (!error)
[[imap4 client] unsubscribe: [[self imap4URL] path]];
}
else else
error = [NSException exceptionWithName: @"SOGoMailException" error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid" reason: @"IMAP connection is invalid"