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);
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;
}
/**
* 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.
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;
}
/**
* @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';
}
/**