]> granicus.if.org Git - neomutt/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)
committerRichard Russon <rich@flatcap.org>
Tue, 8 Oct 2019 16:43:58 +0000 (17:43 +0100)
Co-authored-by: Richard Russon <rich@flatcap.org>
imap/imap_private.h
imap/message.c
imap/util.c

index a18722caffd3ed49caee401fc2c547d3f0413031..18cf752a024049d1f4b1148e6486feacb3bc8262 100644 (file)
@@ -317,7 +317,7 @@ struct ImapMboxData *imap_mdata_new(struct ImapAccountData *adata, const char* n
 void imap_mdata_free(void **ptr);
 void imap_mdata_cache_reset(struct ImapMboxData *mdata);
 char *imap_fix_path(char delim, const char *mailbox, char *path, size_t plen);
-void imap_cachepath(char delim, const char *mailbox, char *dest, size_t dlen);
+void imap_cachepath(char delim, const char *mailbox, struct 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 181f06585af05719f4de3c58fba20bebfb27ce4a..2b67dd671c98f6f61586ced3ffe9c69e4a348bb7 100644 (file)
@@ -117,14 +117,16 @@ static struct BodyCache *msg_cache_open(struct Mailbox *m)
   if (!adata || (adata->mailbox != m))
     return NULL;
 
-  char mailbox[PATH_MAX];
-
   if (mdata->bcache)
     return mdata->bcache;
 
-  imap_cachepath(adata->delim, mdata->name, mailbox, sizeof(mailbox));
+  struct Buffer *mailbox = mutt_buffer_pool_get();
+  imap_cachepath(adata->delim, mdata->name, mailbox);
+
+  struct BodyCache *bc = mutt_bcache_open(&adata->conn->account, mutt_b2s(mailbox));
+  mutt_buffer_pool_release(&mailbox);
 
-  return mutt_bcache_open(&adata->conn->account, mailbox);
+  return bc;
 }
 
 /**
@@ -1232,7 +1234,7 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin,
      * FETCH, nor when no command is in progress (e.g. between the
      * chunked FETCH commands).  We previously tried to be robust by
      * setting:
-     *   msn_begin = idata->max_msn + 1;
+     *   msn_begin = mdata->max_msn + 1;
      * but with chunking (and the mythical header cache holes) this
      * may not be correct.  So here we must assume the msn values have
      * not been altered during or after the fetch.
index d15ad627da82efb7b46d485992b949fbc4c216ba..34cd7d5f84b2efb6fe4c0a2117dfa2af90fbdeac 100644 (file)
@@ -417,23 +417,32 @@ header_cache_t *imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxD
   if (!adata || !mdata)
     return NULL;
 
-  struct Url url;
-  char cachepath[PATH_MAX];
-  char mbox[PATH_MAX];
+  header_cache_t *hc = NULL;
+  struct Buffer *mbox = mutt_buffer_pool_get();
+  struct Buffer *cachepath = mutt_buffer_pool_get();
 
-  imap_cachepath(adata->delim, mdata->name, mbox, sizeof(mbox));
+  imap_cachepath(adata->delim, mdata->name, mbox);
 
-  if (strstr(mbox, "/../") || (strcmp(mbox, "..") == 0) || (strncmp(mbox, "../", 3) == 0))
-    return NULL;
-  size_t 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;
+  }
+  size_t len = mutt_buffer_len(mbox);
+  if ((len > 3) && (strcmp(mutt_b2s(mbox) + len - 3, "/..") == 0))
+    goto cleanup;
 
+  struct Url url;
   mutt_account_tourl(&adata->conn->account, &url);
-  url.path = mbox;
-  url_tostring(&url, cachepath, sizeof(cachepath), U_PATH);
+  url.path = mbox->data;
+  url_tobuffer(&url, cachepath, U_PATH);
 
-  return mutt_hcache_open(C_HeaderCache, cachepath, imap_hcache_namer);
+  hc = mutt_hcache_open(C_HeaderCache, mutt_b2s(cachepath), imap_hcache_namer);
+
+cleanup:
+  mutt_buffer_pool_release(&mbox);
+  mutt_buffer_pool_release(&cachepath);
+  return hc;
 }
 
 /**
@@ -821,31 +830,27 @@ char *imap_fix_path(char server_delim, const char *mailbox, char *path, size_t p
  * @param delim   Imap server delimiter
  * @param mailbox Mailbox name
  * @param dest    Buffer to store cache path
- * @param dlen    Length of buffer
  */
-void imap_cachepath(char delim, const char *mailbox, char *dest, size_t dlen)
+void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest)
 {
-  char *s = NULL;
   const char *p = mailbox;
+  mutt_buffer_reset(dest);
+  if (!p)
+    return;
 
-  for (s = dest; p && (p[0] != '\0') && (dlen > 0); dlen--)
+  while (*p)
   {
     if (p[0] == 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';
 }
 
 /**