diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 50f34f0ba..4ddd1427b 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -793,10 +793,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{
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 (![imapGUIDs allKeysForObject: cKey])
{
@@ -807,7 +803,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[o setTableUrl: [self folderTableURL]];
[o reloadIfNeeded];
- if ([cKey hasPrefix: @"folder"])
+ if ([cKey hasPrefix: @"folder"] || [cKey isEqualToString:@"(null)"])
{
[commands appendFormat: @"%@", [[NSString stringWithFormat: @"mail/%@", [cKey substringFromIndex: 6]] stringByEscapingURL]] ;
command_count++;
@@ -849,6 +845,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
folderMetadata = [allFoldersMetadata objectAtIndex: i];
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]];
name = [folderMetadata objectForKey: @"displayName"];
diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m
index 772c49ecd..97057a1c4 100644
--- a/SoObjects/Mailer/SOGoMailAccount.m
+++ b/SoObjects/Mailer/SOGoMailAccount.m
@@ -40,6 +40,7 @@
#import
#import
#import
+#import
#import
#import
@@ -667,19 +668,14 @@ static NSString *inboxFolderName = @"INBOX";
NSDictionary *result, *nresult, *namespaceDict;
NSMutableDictionary *folders;
NGImap4Client *client;
- SOGoUserDefaults *ud;
NSArray *folderList;
NSEnumerator *e;
NSString *guid;
id object;
- BOOL subscribedOnly, hasAnnotatemore;
+ BOOL hasAnnotatemore;
- ud = [[context activeUser] userDefaults];
- subscribedOnly = [ud mailShowSubscribedFoldersOnly];
-
- folderList = [[self imap4Connection] allFoldersForURL: [self imap4URL]
- onlySubscribedFolders: subscribedOnly];
+ folderList = [self allFolderPaths];
folders = [NSMutableDictionary dictionary];
@@ -688,19 +684,19 @@ static NSString *inboxFolderName = @"INBOX";
hasAnnotatemore = [self hasCapability: @"annotatemore"];
if (hasAnnotatemore)
- result = [client annotation: @"*" entryName: @"/comment" attributeName: @"value.priv"];
+ result = [client annotation: @"*" entryName: @"/comment" attributeName: @"value.priv"];
else
- result = [client lstatus: @"*" flags: [NSArray arrayWithObjects: @"x-guid", nil]];
-
+ result = [client lstatus: @"*" flags: [NSArray arrayWithObjects: @"x-guid", nil]];
+
e = [folderList objectEnumerator];
-
+
while ((object = [e nextObject]))
{
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
- guid = [[[result objectForKey: @"status"] objectForKey: [object substringFromIndex: 1]] objectForKey: @"x-guid"];
-
+ guid = [[[result objectForKey: @"status"] objectForKey: [object substringFromIndex: 1]] objectForKey: @"x-guid"];
+
if (!guid)
{
// 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]]];
continue;
}
-
- guid = [[NSProcessInfo processInfo] globallyUniqueString];
- nresult = [client annotation: [object substringFromIndex: 1] entryName: @"/comment" attributeName: @"value.priv" attributeValue: guid];
- if (![[nresult objectForKey: @"result"] boolValue])
- guid = [NSString stringWithFormat: @"%@", [object substringFromIndex: 1]];
+ // if folder doesn't exists - ignore it
+ 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]]];
-
+
}
-
+
return folders;
}
diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m
index 3607b9dd2..d83ca78a6 100644
--- a/SoObjects/Mailer/SOGoMailFolder.m
+++ b/SoObjects/Mailer/SOGoMailFolder.m
@@ -1069,7 +1069,11 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
NSException *error;
if ([self imap4Connection])
- error = [imap4 deleteMailboxAtURL: [self imap4URL]];
+ {
+ error = [imap4 deleteMailboxAtURL: [self imap4URL]];
+ if (!error)
+ [[imap4 client] unsubscribe: [[self imap4URL] path]];
+ }
else
error = [NSException exceptionWithName: @"SOGoMailException"
reason: @"IMAP connection is invalid"