 ===================================================================
 --- sope-mime/NGImap4/ChangeLog	(revision 1664)
 +++ sope-mime/NGImap4/ChangeLog	(working copy)
-@@ -1,3 +1,99 @@
+@@ -1,3 +1,107 @@
++2010-01-15  Wolfgang Sourdeau  <wsourdeau@inverse.ca>
++
++	* NGImap4Connection.m (-doesMailboxExistAtURL:): sometimes an
++	entry is present in the subfolders cache. When it is the case, the
++	method was returning at the end of the first iteration even though
++	the mailbox was never found. We need to continue and then proceed
++	to the "status" check whether the cache is populated or not.
++
 +2010-01-14  Wolfgang Sourdeau  <wsourdeau@inverse.ca>
 +
 +	* NGImap4Connection.m (-doesMailboxExistAtURL:): mailbox paths can

   if (![[result valueForKey:@"result"] boolValue]) {
     return [self errorForResult:result 
 		 text:@"Failed to change flags of IMAP4 message"];
@@ -737,20 +770,21 @@
 
 - (BOOL)doesMailboxExistAtURL:(NSURL *)_url {
   NSString *folderName;
+  NSArray *caches;
   id result;
+  int count, max;
 
   /* check in hierarchy cache */
-  
-  if ((result = [self cachedHierarchyResults]) != nil) {
+  caches = [self->subfolders allValues];
+  max = [caches count];
+  for (count = 0; count < max; count++) {
     NSString *p;
-    
-    result = [(NSDictionary *)result objectForKey:@"list"];

-#endif
     if ([p hasSuffix:@"/"])
       p = [p substringToIndex:[p length]-1];
-    return ([(NSDictionary *)result objectForKey:p] != nil) ? YES : NO;
+    found = ([(NSDictionary *)result objectForKey:p] != nil);
   }
+
+  if (!found) {
+    /* check using IMAP4 select */
+    // TODO: we should probably just fetch the whole hierarchy?
   
-  /* check using IMAP4 select */
-  // TODO: we should probably just fetch the whole hierarchy?
-  
-  folderName = [self imap4FolderNameForURL:_url];
-  result = [[self client] select:folderName];
-  if (![[result valueForKey:@"result"] boolValue])
-    return NO;
-  
-  return YES;
+    folderName = [self imap4FolderNameForURL:_url];
+
+    result = [self->client status: folderName
+                            flags: [NSArray arrayWithObject: @"UIDVALIDITY"]];
+
+    found =([[result valueForKey: @"result"] boolValue]);
+  }
+
+  return found;
 }
 
 - (id)infoForMailboxAtURL:(NSURL *)_url {
@@ -789,7 +830,8 @@
   /* construct path */
   
   newPath = [self imap4FolderNameForURL:_url];
