From: Mehdi Abaakouk Date: Sat, 8 Dec 2018 19:37:51 +0000 (+0100) Subject: imap: imap_fix/cache_path don't need ImapAccountData X-Git-Tag: 2019-10-25~443^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a7b4aa5dd676ed4e6e34308d8d3c2470049d5a9c;p=neomutt imap: imap_fix/cache_path don't need ImapAccountData --- diff --git a/imap/browse.c b/imap/browse.c index e86e2a108..5eeffbb41 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -225,7 +225,7 @@ int imap_browse(char *path, struct BrowserState *state) /* skip check for parents when at the root */ if (buf[0] != '\0') { - imap_fix_path(adata, buf, mbox, sizeof(mbox)); + imap_fix_path(adata->delim, buf, mbox, sizeof(mbox)); n = mutt_str_strlen(mbox); } else @@ -444,7 +444,7 @@ int imap_mailbox_rename(const char *path) goto err; } - imap_fix_path(adata, newname, buf, sizeof(buf)); + imap_fix_path(adata->delim, newname, buf, sizeof(buf)); if (imap_rename_mailbox(adata, mdata->name, buf) < 0) { diff --git a/imap/imap.c b/imap/imap.c index 5e84664c4..d672ad159 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2498,7 +2498,7 @@ int imap_path_canon(char *buf, size_t buflen) struct Url *url = url_parse(buf); if (url) { - imap_fix_path(NULL, url->path, tmp, sizeof(tmp)); + imap_fix_path('\0', url->path, tmp, sizeof(tmp)); url->path = tmp; url_tostring(url, tmp2, sizeof(tmp2), 0); mutt_str_strfcpy(buf, tmp2, buflen); diff --git a/imap/imap_private.h b/imap/imap_private.h index 781bcfc44..1e4231e64 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -332,8 +332,8 @@ void imap_adata_free(void **ptr); struct ImapMboxData *imap_mdata_new(struct ImapAccountData *adata, const char* name); void imap_mdata_free(void **ptr); void imap_mdata_cache_reset(struct ImapMboxData *mdata); -char *imap_fix_path(struct ImapAccountData *adata, const char *mailbox, char *path, size_t plen); -void imap_cachepath(struct ImapAccountData *adata, const char *mailbox, char *dest, size_t dlen); +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); 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); diff --git a/imap/message.c b/imap/message.c index d24e782c6..6d7c68a69 100644 --- a/imap/message.c +++ b/imap/message.c @@ -124,7 +124,7 @@ static struct BodyCache *msg_cache_open(struct Mailbox *m) if (mdata->bcache) return mdata->bcache; - imap_cachepath(adata, mdata->name, mailbox, sizeof(mailbox)); + imap_cachepath(adata->delim, mdata->name, mailbox, sizeof(mailbox)); return mutt_bcache_open(&adata->conn->account, mailbox); } @@ -1576,7 +1576,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de return 1; } - imap_fix_path(adata, buf, mbox, sizeof(mbox)); + imap_fix_path(adata->delim, buf, mbox, sizeof(mbox)); if (!*mbox) mutt_str_strfcpy(mbox, "INBOX", sizeof(mbox)); imap_munge_mbox_name(adata->unicode, mmbox, sizeof(mmbox), mbox); diff --git a/imap/util.c b/imap/util.c index 324dd12e7..95050fe87 100644 --- a/imap/util.c +++ b/imap/util.c @@ -159,7 +159,7 @@ struct ImapMboxData *imap_mdata_new(struct ImapAccountData *adata, const char *n mdata->real_name = mutt_str_strdup(name); - imap_fix_path(adata, name, buf, sizeof(buf)); + imap_fix_path(adata->delim, name, buf, sizeof(buf)); if (buf[0] == '\0') mutt_str_strfcpy(buf, "INBOX", sizeof(buf)); mdata->name = mutt_str_strdup(buf); @@ -423,7 +423,7 @@ header_cache_t *imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxD char cachepath[PATH_MAX]; char mbox[PATH_MAX]; - imap_cachepath(adata, mdata->name, mbox, sizeof(mbox)); + imap_cachepath(adata->delim, mdata->name, mbox, sizeof(mbox)); if (strstr(mbox, "/../") || (strcmp(mbox, "..") == 0) || (strncmp(mbox, "../", 3) == 0)) return NULL; @@ -673,8 +673,8 @@ int imap_mxcmp(const char *mx1, const char *mx2) b1 = mutt_mem_malloc(strlen(mx1) + 1); b2 = mutt_mem_malloc(strlen(mx2) + 1); - imap_fix_path(NULL, mx1, b1, strlen(mx1) + 1); - imap_fix_path(NULL, mx2, b2, strlen(mx2) + 1); + imap_fix_path('\0', mx1, b1, strlen(mx1) + 1); + imap_fix_path('\0', mx2, b2, strlen(mx2) + 1); rc = mutt_str_strcmp(b1, b2); FREE(&b1); @@ -772,11 +772,11 @@ void imap_error(const char *where, const char *msg) /** * imap_fix_path - Fix up the imap path - * @param adata Imap Account data - * @param mailbox Mailbox path - * @param path Buffer for the result - * @param plen Length of buffer - * @retval ptr Fixed-up path + * @param server_delim Imap Server Delim + * @param mailbox Mailbox path + * @param path Buffer for the result + * @param plen Length of buffer + * @retval ptr Fixed-up path * * This is necessary because the rest of neomutt assumes a hierarchy delimiter of * '/', which is not necessarily true in IMAP. Additionally, the filesystem @@ -784,20 +784,17 @@ void imap_error(const char *where, const char *msg) * to "/". IMAP servers are not required to do this. * Moreover, IMAP servers may dislike the path ending with the delimiter. */ -char *imap_fix_path(struct ImapAccountData *adata, const char *mailbox, char *path, size_t plen) +char *imap_fix_path(char server_delim, const char *mailbox, char *path, size_t plen) { int i = 0; - char delim = '\0'; - - if (adata) - delim = adata->delim; + char delim = server_delim; while (mailbox && *mailbox && i < plen - 1) { if ((ImapDelimChars && strchr(ImapDelimChars, *mailbox)) || (delim && *mailbox == delim)) { /* use connection delimiter if known. Otherwise use user delimiter */ - if (!adata) + if (server_delim == '\0') delim = *mailbox; while (*mailbox && ((ImapDelimChars && strchr(ImapDelimChars, *mailbox)) || @@ -823,19 +820,19 @@ char *imap_fix_path(struct ImapAccountData *adata, const char *mailbox, char *pa /** * imap_cachepath - Generate a cache path for a mailbox - * @param adata Imap Account data + * @param delim Imap server delimiter * @param mailbox Mailbox name * @param dest Buffer to store cache path * @param dlen Length of buffer */ -void imap_cachepath(struct ImapAccountData *adata, const char *mailbox, char *dest, size_t dlen) +void imap_cachepath(char delim, const char *mailbox, char *dest, size_t dlen) { char *s = NULL; const char *p = mailbox; for (s = dest; p && *p && dlen; dlen--) { - if (*p == adata->delim) + if (*p == delim) { *s = '/'; /* simple way to avoid collisions with UIDs */