]> granicus.if.org Git - mutt/commitdiff
Add create flag to imap_mboxcache_get
authorBrendan Cully <brendan@kublai.com>
Mon, 2 Apr 2007 17:48:47 +0000 (10:48 -0700)
committerBrendan Cully <brendan@kublai.com>
Mon, 2 Apr 2007 17:48:47 +0000 (10:48 -0700)
imap/command.c
imap/imap.c
imap/imap_private.h
imap/message.c

index dbd76ca5c56084bfd7d16b5a07f7af8c135686c5..7f23a89427adb80d5b7692f663ac4f3dbea2c4da 100644 (file)
@@ -819,23 +819,15 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
   BUFFY* inc;
   IMAP_MBOX mx;
   int count;
-  IMAP_STATUS *status, sb;
-  int olduv, oldun;
+  IMAP_STATUS *status;
+  unsigned int olduv, oldun;
 
   mailbox = imap_next_word (s);
   s = imap_next_word (mailbox);
   *(s - 1) = '\0';
   imap_unmunge_mbox_name (mailbox);
 
-  if (!(status = imap_mboxcache_get (idata, mailbox)))
-  {
-    /* ugly interface - why should I look up what I just added? */
-    memset (&sb, 0, sizeof (IMAP_STATUS));
-    sb.name = mailbox;
-    idata->mboxcache = mutt_add_list_n (idata->mboxcache, &sb, sizeof (IMAP_STATUS));
-    status = imap_mboxcache_get (idata, mailbox);
-    status->name = safe_strdup (mailbox);
-  }
+  status = imap_mboxcache_get (idata, mailbox, 1);
   olduv = status->uidvalidity;
   oldun = status->uidnext;
 
index 8f702d68f01cc4fa975427f5f4b0177acc8a8164..34f292a9e4d034d88e399b753d2235af9b5ba4a2 100644 (file)
@@ -85,7 +85,7 @@ int imap_access (const char* path, int flags)
   }
   FREE (&mx.mbox);
 
-  if (imap_mboxcache_get (idata, mailbox))
+  if (imap_mboxcache_get (idata, mailbox, 0))
   {
     dprint (3, (debugfile, "imap_access: found %s in cache\n", mailbox));
     return 0;
@@ -556,7 +556,7 @@ int imap_open_mailbox (CONTEXT* ctx)
 {
   CONNECTION *conn;
   IMAP_DATA *idata;
-  IMAP_STATUS* status, sb;
+  IMAP_STATUS* status;
   char buf[LONG_STRING];
   char bufout[LONG_STRING];
   int count = 0;
@@ -632,14 +632,8 @@ int imap_open_mailbox (CONTEXT* ctx)
 
   imap_cmd_start (idata, bufout);
 
-  if (!(status = imap_mboxcache_get (idata, idata->mailbox)))
-  {
-    memset (&sb, 0, sizeof (IMAP_STATUS));
-    sb.name = idata->mailbox;
-    idata->mboxcache = mutt_add_list_n (idata->mboxcache, &sb, sizeof (IMAP_STATUS));
-    status = imap_mboxcache_get (idata, idata->mailbox);
-    status->name = safe_strdup (idata->mailbox);
-  }
+  status = imap_mboxcache_get (idata, idata->mailbox, 1);
+
   do
   {
     char *pc;
@@ -1570,14 +1564,14 @@ int imap_status (char* path, int queue)
     imap_exec (idata, buf, 0);
 
   queued = 0;
-  if ((status = imap_mboxcache_get (idata, mbox)))
+  if ((status = imap_mboxcache_get (idata, mbox, 0)))
     return status->messages;
   
   return 0;
 }
 
-/* return cached mailbox stats or NULL */
-IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox)
+/* return cached mailbox stats or NULL if create is 0 */
+IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox, int create)
 {
   LIST* cur;
   IMAP_STATUS* status;
@@ -1600,6 +1594,17 @@ IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox)
   }
   status = NULL;
 
+  /* lame */
+  if (create)
+  {
+    memset (&scache, 0, sizeof (scache));
+    scache.name = (char*)mbox;
+    idata->mboxcache = mutt_add_list_n (idata->mboxcache, &scache,
+                                        sizeof (scache));
+    status = imap_mboxcache_get (idata, mbox, 0);
+    status->name = safe_strdup (mbox);
+  }
+
 #ifdef USE_HCACHE
   path = safe_strdup (idata->ctx->path);
   url_parse_ciss (&url, path);
@@ -1613,13 +1618,6 @@ IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox)
     uidnext = mutt_hcache_fetch_raw (hc, "/UIDNEXT", imap_hcache_keylen);
     if (uidvalidity)
     {
-      /* lame */
-      memset (&scache, 0, sizeof (scache));
-      scache.name = (char*)mbox;
-      idata->mboxcache = mutt_add_list_n (idata->mboxcache, &scache,
-                                          sizeof (scache));
-      status = imap_mboxcache_get (idata, mbox);
-      status->name = safe_strdup (mbox);
       status->uidvalidity = *uidvalidity;
       status->uidnext = uidnext ? *uidnext: 0;
       dprint (3, (debugfile, "mboxcache: hcache uidvalidity %d, uidnext %d\n",
index 6b94593333cda3b019be3b1972114ee46453d922..c7a6b87624f0bbbe27dd6cd03f2f56169c66fda0 100644 (file)
@@ -230,7 +230,8 @@ typedef struct
 /* imap.c */
 int imap_create_mailbox (IMAP_DATA* idata, char* mailbox);
 int imap_rename_mailbox (IMAP_DATA* idata, IMAP_MBOX* mx, const char* newname);
-IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox);
+IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox,
+                                 int create);
 void imap_mboxcache_free (IMAP_DATA* idata);
 int imap_make_msg_set (IMAP_DATA* idata, BUFFER* buf, int flag, int changed,
                        int invert);
index 4a48c45269f1c5753da12ffcb7c82fb4c2e21f65..5f9974188dcaef05ba5946126e1697e2b6044c56 100644 (file)
@@ -327,7 +327,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
     }
   }
 
-  if (maxuid && (status = imap_mboxcache_get (idata, idata->mailbox)))
+  if (maxuid && (status = imap_mboxcache_get (idata, idata->mailbox, 0)))
   status->uidnext = maxuid + 1;
 
 #if USE_HCACHE