]> granicus.if.org Git - mutt/commitdiff
Convert imap_cachepath() and callers to use buffers.
authorKevin McCarthy <kevin@8t8.us>
Tue, 8 Oct 2019 03:24:38 +0000 (11:24 +0800)
committerKevin McCarthy <kevin@8t8.us>
Tue, 8 Oct 2019 03:24:38 +0000 (11:24 +0800)
imap/imap_private.h
imap/message.c
imap/util.c

index 67376d2b9cb9a39d2b4bcd1b8fc0f52711daf4e6..88af5a48aacc45fc339f3be0ab34dab3464506a4 100644 (file)
@@ -314,8 +314,7 @@ IMAP_DATA* imap_new_idata (void);
 void imap_free_idata (IMAP_DATA** idata);
 char* imap_fix_path (IMAP_DATA* idata, const char* mailbox, char* path,
                      size_t plen);
-void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest,
-                    size_t dlen);
+void imap_cachepath(IMAP_DATA *idata, const char *mailbox, BUFFER *dest);
 int imap_get_literal_count (const char* buf, unsigned int* bytes);
 char* imap_get_qualifier (char* buf);
 int imap_mxcmp (const char* mx1, const char* mx2);
index b2c079e523de5fcdfc3d89516b82feb6c085773a..314961c58f50fe3ab120e3ad21d07a3153d1edb0 100644 (file)
@@ -1471,14 +1471,18 @@ out:
 
 static body_cache_t *msg_cache_open (IMAP_DATA *idata)
 {
-  char mailbox[_POSIX_PATH_MAX];
+  BUFFER *mailbox;
+  body_cache_t *rv;
 
   if (idata->bcache)
     return idata->bcache;
 
-  imap_cachepath (idata, idata->mailbox, mailbox, sizeof (mailbox));
+  mailbox = mutt_buffer_pool_get ();
+  imap_cachepath (idata, idata->mailbox, mailbox);
+  rv = mutt_bcache_open (&idata->conn->account, mutt_b2s (mailbox));
+  mutt_buffer_pool_release (&mailbox);
 
-  return mutt_bcache_open (&idata->conn->account, mailbox);
+  return rv;
 }
 
 static FILE* msg_cache_get (IMAP_DATA* idata, HEADER* h)
index 42f07cc29ff9f3e5c0fdd0ee304bd262ac0e5776..c529fd8fba3cde34be87253683844eb1c19ab30c 100644 (file)
@@ -139,32 +139,43 @@ header_cache_t* imap_hcache_open (IMAP_DATA* idata, const char* path)
 {
   IMAP_MBOX mx;
   ciss_url_t url;
-  char cachepath[LONG_STRING];
-  char mbox[LONG_STRING];
+  BUFFER *cachepath = NULL;
+  BUFFER *mbox = NULL;
   size_t len;
+  header_cache_t *rv = NULL;
+
+  mbox = mutt_buffer_pool_get ();
+  cachepath = mutt_buffer_pool_get ();
 
   if (path)
-    imap_cachepath (idata, path, mbox, sizeof (mbox));
+    imap_cachepath (idata, path, mbox);
   else
   {
     if (!idata->ctx || imap_parse_path (idata->ctx->path, &mx) < 0)
-      return NULL;
+      goto cleanup;
 
-    imap_cachepath (idata, mx.mbox, mbox, sizeof (mbox));
+    imap_cachepath (idata, mx.mbox, mbox);
     FREE (&mx.mbox);
   }
 
-  if (strstr(mbox, "/../") || (strcmp(mbox, "..") == 0) || (strncmp(mbox, "../", 3) == 0))
-    return NULL;
-  len = strlen(mbox);
-  if ((len > 3) && (strcmp(mbox + len - 3, "/..") == 0))
-    return NULL;
+  if (strstr (mutt_b2s (mbox), "/../") ||
+      (strcmp (mutt_b2s (mbox), "..") == 0) ||
+      (strncmp(mutt_b2s (mbox), "../", 3) == 0))
+    goto cleanup;
+  len = mutt_buffer_len (mbox);
+  if ((len > 3) && (strcmp(mutt_b2s (mbox) + len - 3, "/..") == 0))
+    goto cleanup;
 
   mutt_account_tourl (&idata->conn->account, &url);
-  url.path = mbox;
-  url_ciss_tostring (&url, cachepath, sizeof (cachepath), U_PATH);
+  url.path = mbox->data;
+  url_ciss_tobuffer (&url, cachepath, U_PATH);
 
-  return mutt_hcache_open (HeaderCache, cachepath, imap_hcache_namer);
+  rv = mutt_hcache_open (HeaderCache, mutt_b2s (cachepath), imap_hcache_namer);
+
+cleanup:
+  mutt_buffer_pool_release (&mbox);
+  mutt_buffer_pool_release (&cachepath);
+  return rv;
 }
 
 void imap_hcache_close (IMAP_DATA* idata)
@@ -548,30 +559,27 @@ char *imap_fix_path (IMAP_DATA *idata, const char *mailbox, char *path,
   return path;
 }
 
-void imap_cachepath(IMAP_DATA* idata, const char* mailbox, char* dest,
-                    size_t dlen)
+void imap_cachepath (IMAP_DATA *idata, const char *mailbox, BUFFER *dest)
 {
-  char* s;
-  const char* p = mailbox;
+  const char *p = mailbox;
 
-  for (s = dest; p && *p && dlen; dlen--)
+  mutt_buffer_clear (dest);
+  if (!p)
+    return;
+
+  while (*p)
   {
     if (*p == idata->delim)
     {
-      *s = '/';
+      mutt_buffer_addch (dest, '/');
       /* simple way to avoid collisions with UIDs */
       if (*(p + 1) >= '0' && *(p + 1) <= '9')
-      {
-       if (--dlen)
-         *++s = '_';
-      }
+        mutt_buffer_addch (dest, '_');
     }
     else
-      *s = *p;
+      mutt_buffer_addch (dest, *p);
     p++;
-    s++;
   }
-  *s = '\0';
 }
 
 /* imap_get_literal_count: write number of bytes in an IMAP literal into