From: Kevin McCarthy Date: Tue, 16 Apr 2019 20:41:10 +0000 (-0700) Subject: Convert struct Buffer->path to a struct Buffer X-Git-Tag: 2019-10-25~221^2~27 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e4133e5cd21c7391d2dabe0461f05dc40b7b3165;p=neomutt Convert struct Buffer->path to a struct Buffer Rename to struct Buffer->pathbuf to make it clear the field is a struct Buffer, and to make sure to catch and review all usages. There are still uses of pathbuf that are truncating and need to be fixed, for example in browser.c and buffy.c. Fix up sidebar usage in one place, that was pointing inside the struct Mailbox->path with a char *. At the same time, change their "short folder" computation to also use a struct Buffer. Co-authored-by: Richard Russon --- diff --git a/browser.c b/browser.c index fea0c96cb..5b82db3e5 100644 --- a/browser.c +++ b/browser.c @@ -781,7 +781,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state, struct MailboxNode *np = NULL; STAILQ_FOREACH(np, &AllMailboxes, entries) { - if (mutt_str_strcmp(mutt_b2s(buf), np->mailbox->path) != 0) + if (mutt_str_strcmp(mutt_b2s(buf), mutt_b2s(np->mailbox->pathbuf)) != 0) break; } @@ -850,7 +850,7 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state) } char buf[PATH_MAX]; - mutt_str_strfcpy(buf, np->mailbox->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(np->mailbox->pathbuf), sizeof(buf)); if (C_BrowserAbbreviateMailboxes) mutt_pretty_mailbox(buf, sizeof(buf)); @@ -862,14 +862,14 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state) continue; case MUTT_NOTMUCH: case MUTT_NNTP: - add_folder(menu, state, np->mailbox->path, np->mailbox->desc, NULL, - np->mailbox, NULL); + add_folder(menu, state, mutt_b2s(np->mailbox->pathbuf), + np->mailbox->desc, NULL, np->mailbox, NULL); continue; default: /* Continue */ break; } - if (lstat(np->mailbox->path, &s) == -1) + if (lstat(mutt_b2s(np->mailbox->pathbuf), &s) == -1) continue; if ((!S_ISREG(s.st_mode)) && (!S_ISDIR(s.st_mode)) && (!S_ISLNK(s.st_mode))) @@ -879,10 +879,10 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state) { struct stat st2; - mutt_buffer_printf(md, "%s/new", np->mailbox->path); + mutt_buffer_printf(md, "%s/new", mutt_b2s(np->mailbox->pathbuf)); if (stat(mutt_b2s(md), &s) < 0) s.st_mtime = 0; - mutt_buffer_printf(md, "%s/cur", np->mailbox->path); + mutt_buffer_printf(md, "%s/cur", mutt_b2s(np->mailbox->pathbuf)); if (stat(mutt_b2s(md), &st2) < 0) st2.st_mtime = 0; if (st2.st_mtime > s.st_mtime) @@ -1612,7 +1612,8 @@ void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, // TODO(sileht): It could be better to select INBOX instead. But I // don't want to manipulate Context/AllMailboxes/mailbox->account here for now. // Let's just protect neomutt against crash for now. #1417 - if (mutt_str_strcmp(Context->mailbox->path, state.entry[nentry].name) == 0) + if (mutt_str_strcmp(mutt_b2s(Context->mailbox->pathbuf), + state.entry[nentry].name) == 0) { mutt_error(_("Can't delete currently selected mailbox")); break; diff --git a/compose.c b/compose.c index 09f748575..df0b22f7a 100644 --- a/compose.c +++ b/compose.c @@ -1414,7 +1414,7 @@ int mutt_compose_menu(struct Email *msg, char *fcc, size_t fcclen, struct Email if ((op == OP_COMPOSE_ATTACH_MESSAGE) ^ (Context->mailbox->magic == MUTT_NNTP)) #endif { - mutt_str_strfcpy(buf, Context->mailbox->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(Context->mailbox->pathbuf), sizeof(buf)); mutt_pretty_mailbox(buf, sizeof(buf)); } @@ -1910,7 +1910,7 @@ int mutt_compose_menu(struct Email *msg, char *fcc, size_t fcclen, struct Email buf[0] = '\0'; if (Context) { - mutt_str_strfcpy(buf, Context->mailbox->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(Context->mailbox->pathbuf), sizeof(buf)); mutt_pretty_mailbox(buf, sizeof(buf)); } if (actx->idxlen) diff --git a/compress.c b/compress.c index 4b3fb0865..ea278c3ba 100644 --- a/compress.c +++ b/compress.c @@ -140,13 +140,13 @@ static int setup_paths(struct Mailbox *m) char tmp[PATH_MAX]; /* Setup the right paths */ - mutt_str_replace(&m->realpath, m->path); + mutt_str_replace(&m->realpath, mutt_b2s(m->pathbuf)); /* We will uncompress to /tmp */ mutt_mktemp(tmp, sizeof(tmp)); - mutt_str_strfcpy(m->path, tmp, sizeof(m->path)); + mutt_buffer_strcpy(m->pathbuf, tmp); - FILE *fp = mutt_file_fopen(m->path, "w"); + FILE *fp = mutt_file_fopen(mutt_b2s(m->pathbuf), "w"); if (!fp) return -1; @@ -215,12 +215,12 @@ static struct CompressInfo *set_compress_info(struct Mailbox *m) return m->compress_info; /* Open is compulsory */ - const char *o = find_hook(MUTT_OPEN_HOOK, m->path); + const char *o = find_hook(MUTT_OPEN_HOOK, mutt_b2s(m->pathbuf)); if (!o) return NULL; - const char *c = find_hook(MUTT_CLOSE_HOOK, m->path); - const char *a = find_hook(MUTT_APPEND_HOOK, m->path); + const char *c = find_hook(MUTT_CLOSE_HOOK, mutt_b2s(m->pathbuf)); + const char *a = find_hook(MUTT_APPEND_HOOK, mutt_b2s(m->pathbuf)); struct CompressInfo *ci = mutt_mem_calloc(1, sizeof(struct CompressInfo)); m->compress_info = ci; @@ -278,7 +278,7 @@ static const char *compress_format_str(char *buf, size_t buflen, size_t col, int break; case 't': /* Plaintext, temporary file */ - stuffing = mutt_path_escape(m->path); + stuffing = mutt_path_escape(mutt_b2s(m->pathbuf)); break; } snprintf(buf, buflen, "%s", NONULL(stuffing)); @@ -377,7 +377,8 @@ bool mutt_comp_can_append(struct Mailbox *m) if (ci->cmd_append || ci->cmd_close) return true; - mutt_error(_("Can't append without an append-hook or close-hook : %s"), m->path); + mutt_error(_("Can't append without an append-hook or close-hook : %s"), + mutt_b2s(m->pathbuf)); return false; } @@ -464,7 +465,7 @@ static int comp_mbox_open(struct Mailbox *m) return -1; /* If there's no close-hook, or the file isn't writable */ - if (!ci->cmd_close || (access(m->path, W_OK) != 0)) + if (!ci->cmd_close || (access(mutt_b2s(m->pathbuf), W_OK) != 0)) m->readonly = true; if (setup_paths(m) != 0) @@ -483,7 +484,7 @@ static int comp_mbox_open(struct Mailbox *m) unlock_realpath(m); - m->magic = mx_path_probe(m->path, NULL); + m->magic = mx_path_probe(mutt_b2s(m->pathbuf), NULL); if (m->magic == MUTT_UNKNOWN) { mutt_error(_("Can't identify the contents of the compressed file")); @@ -502,7 +503,7 @@ static int comp_mbox_open(struct Mailbox *m) cmo_fail: /* remove the partial uncompressed file */ - remove(m->path); + remove(mutt_b2s(m->pathbuf)); free_compress_info(m); return -1; } @@ -528,7 +529,8 @@ static int comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) /* To append we need an append-hook or a close-hook */ if (!ci->cmd_append && !ci->cmd_close) { - mutt_error(_("Can't append without an append-hook or close-hook : %s"), m->path); + mutt_error(_("Can't append without an append-hook or close-hook : %s"), + mutt_b2s(m->pathbuf)); goto cmoa_fail1; } @@ -552,7 +554,7 @@ static int comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) mutt_error(_("Compress command failed: %s"), ci->cmd_open); goto cmoa_fail2; } - m->magic = mx_path_probe(m->path, NULL); + m->magic = mx_path_probe(mutt_b2s(m->pathbuf), NULL); } else m->magic = C_MboxType; @@ -578,7 +580,7 @@ static int comp_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) cmoa_fail2: /* remove the partial uncompressed file */ - remove(m->path); + remove(mutt_b2s(m->pathbuf)); cmoa_fail1: /* Free the compress_info to prevent close from trying to recompress */ free_compress_info(m); @@ -727,23 +729,23 @@ static int comp_mbox_close(struct Mailbox *m) if (rc == 0) { mutt_any_key_to_continue(NULL); - mutt_error(_("Error. Preserving temporary file: %s"), m->path); + mutt_error(_("Error. Preserving temporary file: %s"), mutt_b2s(m->pathbuf)); } else - remove(m->path); + remove(mutt_b2s(m->pathbuf)); unlock_realpath(m); } else { /* If the file was removed, remove the compressed folder too */ - if ((access(m->path, F_OK) != 0) && !C_SaveEmpty) + if ((access(mutt_b2s(m->pathbuf), F_OK) != 0) && !C_SaveEmpty) { remove(m->realpath); } else { - remove(m->path); + remove(mutt_b2s(m->pathbuf)); } } diff --git a/hdrline.c b/hdrline.c index a548018bd..a47e2a402 100644 --- a/hdrline.c +++ b/hdrline.c @@ -631,11 +631,11 @@ static const char *index_format_str(char *buf, size_t buflen, size_t col, int co case 'b': if (m) { - p = strrchr(m->path, '/'); + p = strrchr(mutt_b2s(m->pathbuf), '/'); if (p) mutt_str_strfcpy(buf, p + 1, buflen); else - mutt_str_strfcpy(buf, m->path, buflen); + mutt_str_strfcpy(buf, mutt_b2s(m->pathbuf), buflen); } else mutt_str_strfcpy(buf, "(null)", buflen); diff --git a/imap/browse.c b/imap/browse.c index 881744c21..3d6d10aee 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -118,7 +118,7 @@ static void add_folder(char delim, char *folder, bool noselect, bool noinferiors struct MailboxNode *np = NULL; STAILQ_FOREACH(np, &AllMailboxes, entries) { - if (mutt_str_strcmp(tmp, np->mailbox->path) == 0) + if (mutt_str_strcmp(tmp, mutt_b2s(np->mailbox->pathbuf)) == 0) break; } diff --git a/imap/imap.c b/imap/imap.c index e33314020..be109ea4f 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -520,16 +520,16 @@ static int complete_hosts(char *buf, size_t buflen) struct MailboxNode *np = NULL; STAILQ_FOREACH(np, &AllMailboxes, entries) { - if (!mutt_str_startswith(np->mailbox->path, buf, CASE_MATCH)) + if (!mutt_str_startswith(mutt_b2s(np->mailbox->pathbuf), buf, CASE_MATCH)) continue; if (rc) { - mutt_str_strfcpy(buf, np->mailbox->path, buflen); + mutt_str_strfcpy(buf, mutt_b2s(np->mailbox->pathbuf), buflen); rc = 0; } else - longest_common_prefix(buf, np->mailbox->path, matchlen, buflen); + longest_common_prefix(buf, mutt_b2s(np->mailbox->pathbuf), matchlen, buflen); } #if 0 @@ -1541,7 +1541,7 @@ int imap_fast_trash(struct Mailbox *m, char *dest) /* check that the save-to folder is in the same account */ if (!mutt_account_match(&(adata->conn->account), &(dest_adata->conn->account))) { - mutt_debug(LL_DEBUG3, "%s not same server as %s\n", dest, m->path); + mutt_debug(LL_DEBUG3, "%s not same server as %s\n", dest, mutt_b2s(m->pathbuf)); goto out; } @@ -1856,7 +1856,7 @@ int imap_ac_add(struct Account *a, struct Mailbox *m) struct ConnAccount conn_account; char mailbox[PATH_MAX]; - if (imap_parse_path(m->path, &conn_account, mailbox, sizeof(mailbox)) < 0) + if (imap_parse_path(mutt_b2s(m->pathbuf), &conn_account, mailbox, sizeof(mailbox)) < 0) return -1; adata = imap_adata_new(); @@ -1876,14 +1876,14 @@ int imap_ac_add(struct Account *a, struct Mailbox *m) if (!m->mdata) { - struct Url *url = url_parse(m->path); + struct Url *url = url_parse(mutt_b2s(m->pathbuf)); struct ImapMboxData *mdata = imap_mdata_new(adata, url->path); /* fixup path and realpath, mainly to replace / by /INBOX */ char buf[1024]; imap_qualify_path(buf, sizeof(buf), &adata->conn_account, mdata->name); - mutt_str_strfcpy(m->path, buf, sizeof(m->path)); - mutt_str_replace(&m->realpath, m->path); + mutt_buffer_strcpy(m->pathbuf, buf); + mutt_str_replace(&m->realpath, mutt_b2s(m->pathbuf)); m->mdata = mdata; m->free_mdata = imap_mdata_free; diff --git a/imap/message.c b/imap/message.c index 3f878a063..3f7a4b802 100644 --- a/imap/message.c +++ b/imap/message.c @@ -1563,7 +1563,7 @@ int imap_copy_messages(struct Mailbox *m, struct EmailList *el, char *dest, bool /* check that the save-to folder is in the same account */ if (!mutt_account_match(&adata->conn->account, &conn_account)) { - mutt_debug(LL_DEBUG3, "%s not same server as %s\n", dest, m->path); + mutt_debug(LL_DEBUG3, "%s not same server as %s\n", dest, mutt_b2s(m->pathbuf)); return 1; } diff --git a/index.c b/index.c index 1ab37ae0e..be5c43710 100644 --- a/index.c +++ b/index.c @@ -627,7 +627,7 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m, if (m) { magic = m->magic; - mutt_str_strfcpy(buf, m->path, buflen); + mutt_str_strfcpy(buf, mutt_b2s(m->pathbuf), buflen); } else { @@ -638,7 +638,7 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m, } /* keepalive failure in mutt_enter_fname may kill connection. #3028 */ - if (Context && (Context->mailbox->path[0] == '\0')) + if (Context && (mutt_buffer_is_empty(Context->mailbox->pathbuf))) ctx_free(&Context); if (Context) @@ -652,7 +652,7 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m, new_last_folder = mutt_str_strdup(Context->mailbox->realpath); else #endif - new_last_folder = mutt_str_strdup(Context->mailbox->path); + new_last_folder = mutt_str_strdup(mutt_b2s(Context->mailbox->pathbuf)); *oldcount = Context ? Context->mailbox->msg_count : 0; int check = mx_mbox_close(&Context); @@ -1103,7 +1103,7 @@ int mutt_index_menu(void) check = mx_mbox_check(Context->mailbox, &index_hint); if (check < 0) { - if (!Context->mailbox || (Context->mailbox->path[0] == '\0')) + if (!Context->mailbox || (mutt_buffer_is_empty(Context->mailbox->pathbuf))) { /* fatal error occurred */ ctx_free(&Context); @@ -1922,7 +1922,7 @@ int mutt_index_menu(void) } /* check for a fatal error, or all messages deleted */ - if (Context->mailbox->path[0] == '\0') + if (mutt_buffer_is_empty(Context->mailbox->pathbuf)) ctx_free(&Context); /* if we were in the pager, redisplay the message */ @@ -2220,9 +2220,9 @@ int mutt_index_menu(void) buf[0] = '\0'; if ((op == OP_MAIN_NEXT_UNREAD_MAILBOX) && Context && - (Context->mailbox->path[0] != '\0')) + mutt_buffer_is_empty(Context->mailbox->pathbuf)) { - mutt_str_strfcpy(buf, Context->mailbox->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(Context->mailbox->pathbuf), sizeof(buf)); mutt_pretty_mailbox(buf, sizeof(buf)); mutt_mailbox(Context ? Context->mailbox : NULL, buf, sizeof(buf)); if (buf[0] == '\0') @@ -2237,17 +2237,18 @@ int mutt_index_menu(void) m = mutt_sb_get_highlight(); if (!m) break; - mutt_str_strfcpy(buf, m->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(m->pathbuf), sizeof(buf)); /* Mark the selected dir for the neomutt browser */ - mutt_browser_select_dir(m->path); + mutt_browser_select_dir(mutt_b2s(m->pathbuf)); } #endif else { - if (C_ChangeFolderNext && Context && (Context->mailbox->path[0] != '\0')) + if (C_ChangeFolderNext && Context && + mutt_buffer_is_empty(Context->mailbox->pathbuf)) { - mutt_str_strfcpy(buf, Context->mailbox->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(Context->mailbox->pathbuf), sizeof(buf)); mutt_pretty_mailbox(buf, sizeof(buf)); } #ifdef USE_NNTP diff --git a/init.c b/init.c index c44cd21f0..f2409674c 100644 --- a/init.c +++ b/init.c @@ -1335,7 +1335,7 @@ static enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s, continue; } - mutt_str_strfcpy(m->path, buf->data, sizeof(m->path)); + mutt_buffer_strcpy(m->pathbuf, buf->data); /* int rc = */ mx_path_canon2(m, C_Folder); bool new_account = false; @@ -2403,7 +2403,7 @@ static enum CommandResult parse_unmailboxes(struct Buffer *buf, struct Buffer *s /* Compare against path or desc? Ensure 'tmp' is valid */ if (!clear_this && tmp_valid) { - clear_this = (mutt_str_strcasecmp(tmp, np->mailbox->path) == 0) || + clear_this = (mutt_str_strcasecmp(tmp, mutt_b2s(np->mailbox->pathbuf)) == 0) || (mutt_str_strcasecmp(tmp, np->mailbox->desc) == 0); } @@ -3232,7 +3232,7 @@ int mutt_init(bool skip_sys_rc, struct ListHead *commands) { if (mp->mailbox->magic == MUTT_NOTMUCH) { - cs_str_string_set(Config, "spoolfile", mp->mailbox->path, NULL); + cs_str_string_set(Config, "spoolfile", mutt_b2s(mp->mailbox->pathbuf), NULL); break; } } diff --git a/mailbox.c b/mailbox.c index 3978614e6..647cc8787 100644 --- a/mailbox.c +++ b/mailbox.c @@ -93,6 +93,8 @@ struct Mailbox *mailbox_new(void) { struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox)); + m->pathbuf = mutt_buffer_new(); + return m; } @@ -108,6 +110,7 @@ void mailbox_free(struct Mailbox **ptr) struct Mailbox *m = *ptr; mutt_mailbox_changed(m, MBN_CLOSED); + mutt_buffer_free(&m->pathbuf); FREE(&m->desc); if (m->mdata && m->free_mdata) m->free_mdata(&m->mdata); @@ -134,7 +137,7 @@ static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, int orig_flagged = m_check->msg_flagged; #endif - enum MailboxType mb_magic = mx_path_probe(m_check->path, NULL); + enum MailboxType mb_magic = mx_path_probe(mutt_b2s(m_check->pathbuf), NULL); switch (mb_magic) { @@ -149,9 +152,10 @@ static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, default: m_check->has_new = false; - if ((stat(m_check->path, &sb) != 0) || (S_ISREG(sb.st_mode) && (sb.st_size == 0)) || + if ((stat(mutt_b2s(m_check->pathbuf), &sb) != 0) || + (S_ISREG(sb.st_mode) && (sb.st_size == 0)) || ((m_check->magic == MUTT_UNKNOWN) && - ((m_check->magic = mx_path_probe(m_check->path, NULL)) <= 0))) + ((m_check->magic = mx_path_probe(mutt_b2s(m_check->pathbuf), NULL)) <= 0))) { /* if the mailbox still doesn't exist, set the newly created flag to be * ready for when it does. */ @@ -164,10 +168,10 @@ static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, } /* check to see if the folder is the currently selected folder before polling */ - if (!m_cur || (m_cur->path[0] == '\0') || + if (!m_cur || mutt_buffer_is_empty(m_cur->pathbuf) || (((m_check->magic == MUTT_IMAP) || (m_check->magic == MUTT_NNTP) || (m_check->magic == MUTT_NOTMUCH) || (m_check->magic == MUTT_POP)) ? - (mutt_str_strcmp(m_check->path, m_cur->path) != 0) : + (mutt_str_strcmp(mutt_b2s(m_check->pathbuf), mutt_b2s(m_cur->pathbuf)) != 0) : ((sb.st_dev != ctx_sb->st_dev) || (sb.st_ino != ctx_sb->st_ino)))) { switch (m_check->magic) @@ -184,7 +188,7 @@ static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, default:; /* do nothing */ } } - else if (C_CheckMboxSize && m_cur && (m_cur->path[0] != '\0')) + else if (C_CheckMboxSize && m_cur && mutt_buffer_is_empty(m_cur->pathbuf)) m_check->size = (off_t) sb.st_size; /* update the size of current folder */ #ifdef USE_SIDEBAR @@ -274,7 +278,7 @@ struct Mailbox *mutt_find_mailbox(const char *path) struct MailboxNode *np = NULL; STAILQ_FOREACH(np, &AllMailboxes, entries) { - if ((stat(np->mailbox->path, &tmp_sb) == 0) && + if ((stat(mutt_b2s(np->mailbox->pathbuf), &tmp_sb) == 0) && (sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino)) { return np->mailbox; @@ -316,7 +320,7 @@ void mutt_update_mailbox(struct Mailbox *m) if (!m) return; - if (stat(m->path, &sb) == 0) + if (stat(mutt_b2s(m->pathbuf), &sb) == 0) m->size = (off_t) sb.st_size; else m->size = 0; @@ -372,7 +376,7 @@ int mutt_mailbox_check(struct Mailbox *m_cur, int force) #ifdef USE_NNTP || (m_cur->magic == MUTT_NNTP) #endif - || stat(m_cur->path, &contex_sb) != 0) + || stat(mutt_b2s(m_cur->pathbuf), &contex_sb) != 0) { contex_sb.st_dev = 0; contex_sb.st_ino = 0; @@ -411,7 +415,7 @@ bool mutt_mailbox_list(void) if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified)) continue; - mutt_str_strfcpy(path, np->mailbox->path, sizeof(path)); + mutt_str_strfcpy(path, mutt_b2s(np->mailbox->pathbuf), sizeof(path)); mutt_pretty_mailbox(path, sizeof(path)); if (!first && (MuttMessageWindow->cols >= 7) && @@ -502,14 +506,14 @@ void mutt_buffer_mailbox(struct Mailbox *m_cur, struct Buffer *s) { if (np->mailbox->magic == MUTT_NOTMUCH) /* only match real mailboxes */ continue; - mutt_expand_path(np->mailbox->path, sizeof(np->mailbox->path)); + mutt_buffer_expand_path(np->mailbox->pathbuf); if ((found || pass) && np->mailbox->has_new) { - mutt_buffer_strcpy(s, np->mailbox->path); + mutt_buffer_strcpy(s, mutt_b2s(np->mailbox->pathbuf)); mutt_buffer_pretty_mailbox(s); return; } - if (mutt_str_strcmp(mutt_b2s(s), np->mailbox->path) == 0) + if (mutt_str_strcmp(mutt_b2s(s), mutt_b2s(np->mailbox->pathbuf)) == 0) found = 1; } } diff --git a/mailbox.h b/mailbox.h index 1d8d3e324..88b806feb 100644 --- a/mailbox.h +++ b/mailbox.h @@ -82,7 +82,7 @@ typedef uint16_t AclFlags; ///< Flags, e.g. #MUTT_ACL_ADMIN */ struct Mailbox { - char path[PATH_MAX]; + struct Buffer *pathbuf; char *realpath; ///< used for duplicate detection, context comparison, and the sidebar char *desc; off_t size; diff --git a/maildir/maildir.c b/maildir/maildir.c index a657093b7..e17123d88 100644 --- a/maildir/maildir.c +++ b/maildir/maildir.c @@ -78,7 +78,7 @@ static void maildir_check_dir(struct Mailbox *m, const char *dir_name, struct Buffer *path = mutt_buffer_pool_get(); struct Buffer *msgpath = mutt_buffer_pool_get(); - mutt_buffer_printf(path, "%s/%s", m->path, dir_name); + mutt_buffer_printf(path, "%s/%s", mutt_b2s(m->pathbuf), dir_name); /* when $mail_check_recent is set, if the new/ directory hasn't been modified since * the user last exited the m, then we know there is no recent mail. */ @@ -247,8 +247,8 @@ int maildir_sync_message(struct Mailbox *m, int msgno) mutt_buffer_printf(partpath, "%s/%s%s", (e->read || e->old) ? "cur" : "new", mutt_b2s(newpath), suffix); - mutt_buffer_printf(fullpath, "%s/%s", m->path, mutt_b2s(partpath)); - mutt_buffer_printf(oldpath, "%s/%s", m->path, e->path); + mutt_buffer_printf(fullpath, "%s/%s", mutt_b2s(m->pathbuf), mutt_b2s(partpath)); + mutt_buffer_printf(oldpath, "%s/%s", mutt_b2s(m->pathbuf), e->path); if (mutt_str_strcmp(mutt_b2s(fullpath), mutt_b2s(oldpath)) == 0) { @@ -303,40 +303,40 @@ static int maildir_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) return 0; } - if (mkdir(m->path, S_IRWXU)) + if (mkdir(mutt_b2s(m->pathbuf), S_IRWXU)) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } char tmp[PATH_MAX]; - snprintf(tmp, sizeof(tmp), "%s/cur", m->path); + snprintf(tmp, sizeof(tmp), "%s/cur", mutt_b2s(m->pathbuf)); if (mkdir(tmp, S_IRWXU)) { mutt_perror(tmp); - rmdir(m->path); + rmdir(mutt_b2s(m->pathbuf)); return -1; } - snprintf(tmp, sizeof(tmp), "%s/new", m->path); + snprintf(tmp, sizeof(tmp), "%s/new", mutt_b2s(m->pathbuf)); if (mkdir(tmp, S_IRWXU)) { mutt_perror(tmp); - snprintf(tmp, sizeof(tmp), "%s/cur", m->path); + snprintf(tmp, sizeof(tmp), "%s/cur", mutt_b2s(m->pathbuf)); rmdir(tmp); - rmdir(m->path); + rmdir(mutt_b2s(m->pathbuf)); return -1; } - snprintf(tmp, sizeof(tmp), "%s/tmp", m->path); + snprintf(tmp, sizeof(tmp), "%s/tmp", mutt_b2s(m->pathbuf)); if (mkdir(tmp, S_IRWXU)) { mutt_perror(tmp); - snprintf(tmp, sizeof(tmp), "%s/cur", m->path); + snprintf(tmp, sizeof(tmp), "%s/cur", mutt_b2s(m->pathbuf)); rmdir(tmp); - snprintf(tmp, sizeof(tmp), "%s/new", m->path); + snprintf(tmp, sizeof(tmp), "%s/new", mutt_b2s(m->pathbuf)); rmdir(tmp); - rmdir(m->path); + rmdir(mutt_b2s(m->pathbuf)); return -1; } @@ -376,14 +376,14 @@ int maildir_mbox_check(struct Mailbox *m, int *index_hint) return 0; struct Buffer *buf = mutt_buffer_pool_get(); - mutt_buffer_printf(buf, "%s/new", m->path); + mutt_buffer_printf(buf, "%s/new", mutt_b2s(m->pathbuf)); if (stat(mutt_b2s(buf), &st_new) == -1) { mutt_buffer_pool_release(&buf); return -1; } - mutt_buffer_printf(buf, "%s/cur", m->path); + mutt_buffer_printf(buf, "%s/cur", mutt_b2s(m->pathbuf)); if (stat(mutt_b2s(buf), &st_cur) == -1) { mutt_buffer_pool_release(&buf); @@ -596,8 +596,9 @@ int maildir_msg_open_new(struct Mailbox *m, struct Message *msg, struct Email *e mode_t omask = umask(mh_umask(m)); while (true) { - snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s", m->path, subdir, - (long long) time(NULL), mutt_rand64(), NONULL(ShortHostname), suffix); + snprintf(path, sizeof(path), "%s/tmp/%s.%lld.R%" PRIu64 ".%s%s", + mutt_b2s(m->pathbuf), subdir, (long long) time(NULL), + mutt_rand64(), NONULL(ShortHostname), suffix); mutt_debug(LL_DEBUG2, "Trying %s\n", path); @@ -650,7 +651,7 @@ static int maildir_msg_save_hcache(struct Mailbox *m, struct Email *e) { int rc = 0; #ifdef USE_HCACHE - header_cache_t *hc = mutt_hcache_open(C_HeaderCache, m->path, NULL); + header_cache_t *hc = mutt_hcache_open(C_HeaderCache, mutt_b2s(m->pathbuf), NULL); char *key = e->path + 3; int keylen = maildir_hcache_keylen(key); rc = mutt_hcache_store(hc, key, keylen, e, 0); diff --git a/maildir/mh.c b/maildir/mh.c index bd8c0e396..ff7b0ea71 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -194,7 +194,7 @@ void mh_update_sequences(struct Mailbox *m) return; } - snprintf(sequences, sizeof(sequences), "%s/.mh_sequences", m->path); + snprintf(sequences, sizeof(sequences), "%s/.mh_sequences", mutt_b2s(m->pathbuf)); /* first, copy unknown sequences */ FILE *fp_old = fopen(sequences, "r"); @@ -364,7 +364,7 @@ static int mh_sequences_changed(struct Mailbox *m) char path[PATH_MAX]; struct stat sb; - if ((snprintf(path, sizeof(path), "%s/.mh_sequences", m->path) < sizeof(path)) && + if ((snprintf(path, sizeof(path), "%s/.mh_sequences", mutt_b2s(m->pathbuf)) < sizeof(path)) && (stat(path, &sb) == 0)) { return (mutt_file_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) > 0); @@ -385,7 +385,7 @@ static int mh_already_notified(struct Mailbox *m, int msgno) char path[PATH_MAX]; struct stat sb; - if ((snprintf(path, sizeof(path), "%s/%d", m->path, msgno) < sizeof(path)) && + if ((snprintf(path, sizeof(path), "%s/%d", mutt_b2s(m->pathbuf), msgno) < sizeof(path)) && (stat(path, &sb) == 0)) { return (mutt_file_stat_timespec_compare(&sb, MUTT_STAT_MTIME, &m->last_visited) <= 0); @@ -435,7 +435,7 @@ static int mh_mbox_check_stats(struct Mailbox *m, int flags) if (!check_new) return 0; - if (mh_read_sequences(&mhs, m->path) < 0) + if (mh_read_sequences(&mhs, mutt_b2s(m->pathbuf)) < 0) return false; m->msg_count = 0; @@ -468,7 +468,7 @@ static int mh_mbox_check_stats(struct Mailbox *m, int flags) mhs_free_sequences(&mhs); - dirp = opendir(m->path); + dirp = opendir(mutt_b2s(m->pathbuf)); if (dirp) { while ((de = readdir(dirp))) @@ -559,19 +559,19 @@ static int mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) return 0; } - if (mkdir(m->path, S_IRWXU)) + if (mkdir(mutt_b2s(m->pathbuf), S_IRWXU)) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } char tmp[PATH_MAX]; - snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", m->path); + snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", mutt_b2s(m->pathbuf)); const int i = creat(tmp, S_IRWXU); if (i == -1) { mutt_perror(tmp); - rmdir(m->path); + rmdir(mutt_b2s(m->pathbuf)); return -1; } close(i); @@ -608,12 +608,12 @@ int mh_mbox_check(struct Mailbox *m, int *index_hint) if (!C_CheckNew) return 0; - mutt_str_strfcpy(buf, m->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(m->pathbuf), sizeof(buf)); if (stat(buf, &st) == -1) return -1; /* create .mh_sequences when there isn't one. */ - snprintf(buf, sizeof(buf), "%s/.mh_sequences", m->path); + snprintf(buf, sizeof(buf), "%s/.mh_sequences", mutt_b2s(m->pathbuf)); int i = stat(buf, &st_cur); if ((i == -1) && (errno == ENOENT)) { @@ -663,7 +663,7 @@ int mh_mbox_check(struct Mailbox *m, int *index_hint) maildir_parse_dir(m, &last, NULL, &count, NULL); maildir_delayed_parsing(m, &md, NULL); - if (mh_read_sequences(&mhs, m->path) < 0) + if (mh_read_sequences(&mhs, mutt_b2s(m->pathbuf)) < 0) return -1; mh_update_maildir(md, &mhs); mhs_free_sequences(&mhs); diff --git a/maildir/shared.c b/maildir/shared.c index ae760544b..105952f66 100644 --- a/maildir/shared.c +++ b/maildir/shared.c @@ -124,9 +124,9 @@ mode_t mh_umask(struct Mailbox *m) return mdata->mh_umask; struct stat st; - if (stat(m->path, &st)) + if (stat(mutt_b2s(m->pathbuf), &st)) { - mutt_debug(LL_DEBUG1, "stat failed on %s\n", m->path); + mutt_debug(LL_DEBUG1, "stat failed on %s\n", mutt_b2s(m->pathbuf)); return 077; } @@ -149,7 +149,7 @@ int mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt) mode_t omask = umask(mh_umask(m)); while (true) { - snprintf(path, sizeof(path), "%s/.neomutt-%s-%d-%" PRIu64, m->path, + snprintf(path, sizeof(path), "%s/.neomutt-%s-%d-%" PRIu64, mutt_b2s(m->pathbuf), NONULL(ShortHostname), (int) getpid(), mutt_rand64()); fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666); if (fd == -1) @@ -214,7 +214,7 @@ static void mh_sequences_add_one(struct Mailbox *m, int n, bool unseen, bool fla snprintf(seq_replied, sizeof(seq_replied), "%s:", NONULL(C_MhSeqReplied)); snprintf(seq_flagged, sizeof(seq_flagged), "%s:", NONULL(C_MhSeqFlagged)); - snprintf(sequences, sizeof(sequences), "%s/.mh_sequences", m->path); + snprintf(sequences, sizeof(sequences), "%s/.mh_sequences", mutt_b2s(m->pathbuf)); FILE *fp_old = fopen(sequences, "r"); if (fp_old) { @@ -304,18 +304,18 @@ static void maildir_update_mtime(struct Mailbox *m) if (m->magic == MUTT_MAILDIR) { - snprintf(buf, sizeof(buf), "%s/%s", m->path, "cur"); + snprintf(buf, sizeof(buf), "%s/%s", mutt_b2s(m->pathbuf), "cur"); if (stat(buf, &st) == 0) mutt_file_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME); - snprintf(buf, sizeof(buf), "%s/%s", m->path, "new"); + snprintf(buf, sizeof(buf), "%s/%s", mutt_b2s(m->pathbuf), "new"); } else { - snprintf(buf, sizeof(buf), "%s/.mh_sequences", m->path); + snprintf(buf, sizeof(buf), "%s/.mh_sequences", mutt_b2s(m->pathbuf)); if (stat(buf, &st) == 0) mutt_file_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME); - mutt_str_strfcpy(buf, m->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(m->pathbuf), sizeof(buf)); } if (stat(buf, &st) == 0) @@ -346,11 +346,11 @@ int maildir_parse_dir(struct Mailbox *m, struct Maildir ***last, if (subdir) { - mutt_buffer_printf(buf, "%s/%s", m->path, subdir); + mutt_buffer_printf(buf, "%s/%s", mutt_b2s(m->pathbuf), subdir); is_old = C_MarkOld ? (mutt_str_strcmp("cur", subdir) == 0) : false; } else - mutt_buffer_strcpy(buf, m->path); + mutt_buffer_strcpy(buf, mutt_b2s(m->pathbuf)); DIR *dirp = opendir(mutt_b2s(buf)); if (!dirp) @@ -650,7 +650,7 @@ static void mh_sort_natural(struct Mailbox *m, struct Maildir **md) { if (!m || !md || !*md || (m->magic != MUTT_MH) || (C_Sort != SORT_ORDER)) return; - mutt_debug(LL_DEBUG3, "maildir: sorting %s into natural order\n", m->path); + mutt_debug(LL_DEBUG3, "maildir: sorting %s into natural order\n", mutt_b2s(m->pathbuf)); *md = maildir_sort(*md, (size_t) -1, md_cmp_path); } @@ -693,7 +693,7 @@ void maildir_delayed_parsing(struct Mailbox *m, struct Maildir **md, struct Prog bool sort = false; #ifdef USE_HCACHE - header_cache_t *hc = mutt_hcache_open(C_HeaderCache, m->path, NULL); + header_cache_t *hc = mutt_hcache_open(C_HeaderCache, mutt_b2s(m->pathbuf), NULL); #endif for (p = *md, count = 0; p; p = p->next, count++) @@ -709,7 +709,7 @@ void maildir_delayed_parsing(struct Mailbox *m, struct Maildir **md, struct Prog if (!sort) { - mutt_debug(LL_DEBUG3, "maildir: need to sort %s by inode\n", m->path); + mutt_debug(LL_DEBUG3, "maildir: need to sort %s by inode\n", mutt_b2s(m->pathbuf)); p = maildir_sort(p, (size_t) -1, md_cmp_inode); if (!last) *md = p; @@ -717,10 +717,10 @@ void maildir_delayed_parsing(struct Mailbox *m, struct Maildir **md, struct Prog last->next = p; sort = true; p = skip_duplicates(p, &last); - snprintf(fn, sizeof(fn), "%s/%s", m->path, p->email->path); + snprintf(fn, sizeof(fn), "%s/%s", mutt_b2s(m->pathbuf), p->email->path); } - snprintf(fn, sizeof(fn), "%s/%s", m->path, p->email->path); + snprintf(fn, sizeof(fn), "%s/%s", mutt_b2s(m->pathbuf), p->email->path); #ifdef USE_HCACHE struct stat lastchanged = { 0 }; @@ -812,7 +812,7 @@ int mh_read_dir(struct Mailbox *m, const char *subdir) if (!m->quiet) { - snprintf(msgbuf, sizeof(msgbuf), _("Scanning %s..."), m->path); + snprintf(msgbuf, sizeof(msgbuf), _("Scanning %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, 0); } @@ -834,14 +834,14 @@ int mh_read_dir(struct Mailbox *m, const char *subdir) if (!m->quiet) { - snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), m->path); + snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, count); } maildir_delayed_parsing(m, &md, &progress); if (m->magic == MUTT_MH) { - if (mh_read_sequences(&mhs, m->path) < 0) + if (mh_read_sequences(&mhs, mutt_b2s(m->pathbuf)) < 0) { maildir_free_maildir(&md); return -1; @@ -872,11 +872,11 @@ int maildir_mh_open_message(struct Mailbox *m, struct Message *msg, int msgno, b struct Email *cur = m->emails[msgno]; char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/%s", m->path, cur->path); + snprintf(path, sizeof(path), "%s/%s", mutt_b2s(m->pathbuf), cur->path); msg->fp = fopen(path, "r"); if (!msg->fp && (errno == ENOENT) && is_maildir) - msg->fp = maildir_open_find_message(m->path, cur->path, NULL); + msg->fp = maildir_open_find_message(mutt_b2s(m->pathbuf), cur->path, NULL); if (!msg->fp) { @@ -911,10 +911,10 @@ int mh_commit_msg(struct Mailbox *m, struct Message *msg, struct Email *e, bool return -1; } - DIR *dirp = opendir(m->path); + DIR *dirp = opendir(mutt_b2s(m->pathbuf)); if (!dirp) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } @@ -949,7 +949,7 @@ int mh_commit_msg(struct Mailbox *m, struct Message *msg, struct Email *e, bool { hi++; snprintf(tmp, sizeof(tmp), "%u", hi); - snprintf(path, sizeof(path), "%s/%s", m->path, tmp); + snprintf(path, sizeof(path), "%s/%s", mutt_b2s(m->pathbuf), tmp); if (mutt_file_safe_rename(msg->path, path) == 0) { if (e) @@ -960,7 +960,7 @@ int mh_commit_msg(struct Mailbox *m, struct Message *msg, struct Email *e, bool } else if (errno != EEXIST) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } } @@ -1025,7 +1025,7 @@ int md_commit_message(struct Mailbox *m, struct Message *msg, struct Email *e) { mutt_buffer_printf(path, "%s/%lld.R%" PRIu64 ".%s%s", subdir, (long long) time(NULL), mutt_rand64(), NONULL(ShortHostname), suffix); - mutt_buffer_printf(full, "%s/%s", m->path, mutt_b2s(path)); + mutt_buffer_printf(full, "%s/%s", mutt_b2s(m->pathbuf), mutt_b2s(path)); mutt_debug(LL_DEBUG2, "renaming %s to %s\n", msg->path, mutt_b2s(full)); @@ -1062,7 +1062,7 @@ int md_commit_message(struct Mailbox *m, struct Message *msg, struct Email *e) } else if (errno != EEXIST) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); rc = -1; goto cleanup; } @@ -1105,7 +1105,7 @@ int mh_rewrite_message(struct Mailbox *m, int msgno) { char oldpath[PATH_MAX]; char partpath[PATH_MAX]; - snprintf(oldpath, sizeof(oldpath), "%s/%s", m->path, e->path); + snprintf(oldpath, sizeof(oldpath), "%s/%s", mutt_b2s(m->pathbuf), e->path); mutt_str_strfcpy(partpath, e->path, sizeof(partpath)); if (m->magic == MUTT_MAILDIR) @@ -1137,7 +1137,7 @@ int mh_rewrite_message(struct Mailbox *m, int msgno) if ((m->magic == MUTT_MH) && (rc == 0)) { char newpath[PATH_MAX]; - snprintf(newpath, sizeof(newpath), "%s/%s", m->path, e->path); + snprintf(newpath, sizeof(newpath), "%s/%s", mutt_b2s(m->pathbuf), e->path); rc = mutt_file_safe_rename(newpath, oldpath); if (rc == 0) mutt_str_replace(&e->path, partpath); @@ -1413,7 +1413,7 @@ int mh_sync_mailbox_message(struct Mailbox *m, int msgno, header_cache_t *hc) if (e->deleted && ((m->magic != MUTT_MAILDIR) || !C_MaildirTrash)) { char path[PATH_MAX]; - snprintf(path, sizeof(path), "%s/%s", m->path, e->path); + snprintf(path, sizeof(path), "%s/%s", mutt_b2s(m->pathbuf), e->path); if ((m->magic == MUTT_MAILDIR) || (C_MhPurge && (m->magic == MUTT_MH))) { #ifdef USE_HCACHE @@ -1442,7 +1442,7 @@ int mh_sync_mailbox_message(struct Mailbox *m, int msgno, header_cache_t *hc) if (*e->path != ',') { char tmp[PATH_MAX]; - snprintf(tmp, sizeof(tmp), "%s/,%s", m->path, e->path); + snprintf(tmp, sizeof(tmp), "%s/,%s", mutt_b2s(m->pathbuf), e->path); unlink(tmp); rename(path, tmp); } @@ -1741,12 +1741,12 @@ int mh_mbox_sync(struct Mailbox *m, int *index_hint) #ifdef USE_HCACHE if ((m->magic == MUTT_MAILDIR) || (m->magic == MUTT_MH)) - hc = mutt_hcache_open(C_HeaderCache, m->path, NULL); + hc = mutt_hcache_open(C_HeaderCache, mutt_b2s(m->pathbuf), NULL); #endif if (!m->quiet) { - snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), m->path); + snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count); } @@ -1818,7 +1818,7 @@ int mh_msg_save_hcache(struct Mailbox *m, struct Email *e) { int rc = 0; #ifdef USE_HCACHE - header_cache_t *hc = mutt_hcache_open(C_HeaderCache, m->path, NULL); + header_cache_t *hc = mutt_hcache_open(C_HeaderCache, mutt_b2s(m->pathbuf), NULL); rc = mutt_hcache_store(hc, e->path, strlen(e->path), e, 0); mutt_hcache_close(hc); #endif diff --git a/mbox/mbox.c b/mbox/mbox.c index b0e06d09f..95f661aa5 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -198,9 +198,9 @@ static int mmdf_parse_mailbox(struct Mailbox *m) struct stat sb; struct Progress progress; - if (stat(m->path, &sb) == -1) + if (stat(mutt_b2s(m->pathbuf), &sb) == -1) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } mutt_file_get_stat_timespec(&adata->atime, &sb, MUTT_STAT_ATIME); @@ -212,7 +212,7 @@ static int mmdf_parse_mailbox(struct Mailbox *m) if (!m->quiet) { char msgbuf[256]; - snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), m->path); + snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, 0); } @@ -362,9 +362,9 @@ static int mbox_parse_mailbox(struct Mailbox *m) struct Progress progress; /* Save information about the folder at the time we opened it. */ - if (stat(m->path, &sb) == -1) + if (stat(mutt_b2s(m->pathbuf), &sb) == -1) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } @@ -373,12 +373,12 @@ static int mbox_parse_mailbox(struct Mailbox *m) mutt_file_get_stat_timespec(&adata->atime, &sb, MUTT_STAT_ATIME); if (!m->readonly) - m->readonly = access(m->path, W_OK) ? true : false; + m->readonly = access(mutt_b2s(m->pathbuf), W_OK) ? true : false; if (!m->quiet) { char msgbuf[256]; - snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), m->path); + snprintf(msgbuf, sizeof(msgbuf), _("Reading %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_ReadInc, 0); } @@ -619,7 +619,7 @@ static int reopen_mailbox(struct Mailbox *m, int *index_hint) case MUTT_MMDF: cmp_headers = mutt_email_cmp_strict; mutt_file_fclose(&adata->fp); - adata->fp = mutt_file_fopen(m->path, "r"); + adata->fp = mutt_file_fopen(mutt_b2s(m->pathbuf), "r"); if (!adata->fp) rc = -1; else if (m->magic == MUTT_MBOX) @@ -855,7 +855,7 @@ void mbox_reset_atime(struct Mailbox *m, struct stat *st) if (!st) { - if (stat(m->path, &st2) < 0) + if (stat(mutt_b2s(m->pathbuf), &st2) < 0) return; st = &st2; } @@ -870,7 +870,7 @@ void mbox_reset_atime(struct Mailbox *m, struct stat *st) utimebuf.actime = utimebuf.modtime - 1; } - utime(m->path, &utimebuf); + utime(mutt_b2s(m->pathbuf), &utimebuf); } /** @@ -885,7 +885,7 @@ struct Account *mbox_ac_find(struct Account *a, const char *path) if (!np) return NULL; - if (mutt_str_strcmp(np->mailbox->path, path) != 0) + if (mutt_str_strcmp(mutt_b2s(np->mailbox->pathbuf), path) != 0) return NULL; return a; @@ -913,10 +913,10 @@ static int mbox_mbox_open(struct Mailbox *m) if (!adata) return -1; - adata->fp = fopen(m->path, "r+"); + adata->fp = fopen(mutt_b2s(m->pathbuf), "r+"); if (!adata->fp) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } mutt_sig_block(); @@ -955,16 +955,16 @@ static int mbox_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags) if (!adata) return -1; - adata->fp = mutt_file_fopen(m->path, (flags & MUTT_NEWFOLDER) ? "w" : "a"); + adata->fp = mutt_file_fopen(mutt_b2s(m->pathbuf), (flags & MUTT_NEWFOLDER) ? "w" : "a"); if (!adata->fp) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } if (mbox_lock_mailbox(m, true, true) != false) { - mutt_error(_("Couldn't lock %s"), m->path); + mutt_error(_("Couldn't lock %s"), mutt_b2s(m->pathbuf)); mutt_file_fclose(&adata->fp); return -1; } @@ -1004,7 +1004,7 @@ static int mbox_mbox_check(struct Mailbox *m, int *index_hint) bool unlock = false; bool modified = false; - if (stat(m->path, &st) == 0) + if (stat(mutt_b2s(m->pathbuf), &st) == 0) { if ((mutt_file_stat_timespec_compare(&st, MUTT_STAT_MTIME, &m->mtime) == 0) && (st.st_size == m->size)) @@ -1146,7 +1146,7 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint) /* need to open the file for writing in such a way that it does not truncate * the file, so use read-write mode. */ - adata->fp = freopen(m->path, "r+", adata->fp); + adata->fp = freopen(mutt_b2s(m->pathbuf), "r+", adata->fp); if (!adata->fp) { mx_fastclose_mailbox(m); @@ -1226,7 +1226,7 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint) if (!m->quiet) { - snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), m->path); + snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count); } @@ -1310,9 +1310,9 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint) fp = NULL; /* Save the state of this folder. */ - if (stat(m->path, &statbuf) == -1) + if (stat(mutt_b2s(m->pathbuf), &statbuf) == -1) { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); unlink(tempfile); goto bail; } @@ -1394,7 +1394,7 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint) mbox_reset_atime(m, &statbuf); /* reopen the mailbox in read-only mode */ - adata->fp = fopen(m->path, "r"); + adata->fp = fopen(mutt_b2s(m->pathbuf), "r"); if (!adata->fp) { unlink(tempfile); @@ -1424,7 +1424,7 @@ static int mbox_mbox_sync(struct Mailbox *m, int *index_hint) if (C_CheckMboxSize) { - struct Mailbox *tmp = mutt_find_mailbox(m->path); + struct Mailbox *tmp = mutt_find_mailbox(mutt_b2s(m->pathbuf)); if (tmp && !tmp->has_new) mutt_update_mailbox(tmp); } @@ -1455,7 +1455,7 @@ bail: /* Come here in case of disaster */ FREE(&new_offset); FREE(&old_offset); - adata->fp = freopen(m->path, "r", adata->fp); + adata->fp = freopen(mutt_b2s(m->pathbuf), "r", adata->fp); if (!adata->fp) { mutt_error(_("Could not reopen mailbox")); @@ -1497,7 +1497,7 @@ static int mbox_mbox_close(struct Mailbox *m) mutt_file_fclose(&adata->fp); /* fix up the times so mailbox won't get confused */ - if (m->peekonly && (m->path[0] != '\0') && + if (m->peekonly && mutt_buffer_is_empty(m->pathbuf) && (mutt_file_timespec_compare(&m->mtime, &adata->atime) > 0)) { #ifdef HAVE_UTIMENSAT @@ -1509,7 +1509,7 @@ static int mbox_mbox_close(struct Mailbox *m) struct utimbuf ut; ut.actime = adata->atime.tv_sec; ut.modtime = m->mtime.tv_sec; - utime(m->path, &ut); + utime(mutt_b2s(m->pathbuf), &ut); #endif } @@ -1737,7 +1737,7 @@ static int mmdf_msg_padding_size(struct Mailbox *m) static int mbox_mbox_check_stats(struct Mailbox *m, int flags) { struct stat sb = { 0 }; - if (stat(m->path, &sb) != 0) + if (stat(mutt_b2s(m->pathbuf), &sb) != 0) return -1; bool new_or_changed; diff --git a/mx.c b/mx.c index b545f7c16..b0ac47e74 100644 --- a/mx.c +++ b/mx.c @@ -187,7 +187,7 @@ static int mx_open_mailbox_append(struct Mailbox *m, OpenMailboxFlags flags) m->append = true; if ((m->magic == MUTT_UNKNOWN) || (m->magic == MUTT_MAILBOX_ERROR)) { - m->magic = mx_path_probe(m->path, NULL); + m->magic = mx_path_probe(mutt_b2s(m->pathbuf), NULL); if (m->magic == MUTT_UNKNOWN) { @@ -197,14 +197,14 @@ static int mx_open_mailbox_append(struct Mailbox *m, OpenMailboxFlags flags) } else { - mutt_error(_("%s is not a mailbox"), m->path); + mutt_error(_("%s is not a mailbox"), mutt_b2s(m->pathbuf)); return -1; } } if (m->magic == MUTT_MAILBOX_ERROR) { - if (stat(m->path, &sb) == -1) + if (stat(mutt_b2s(m->pathbuf), &sb) == -1) { if (errno == ENOENT) { @@ -218,7 +218,7 @@ static int mx_open_mailbox_append(struct Mailbox *m, OpenMailboxFlags flags) } else { - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); return -1; } } @@ -311,16 +311,16 @@ struct Context *mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags) if (m->magic == MUTT_UNKNOWN) { - m->magic = mx_path_probe(m->path, NULL); + m->magic = mx_path_probe(mutt_b2s(m->pathbuf), NULL); m->mx_ops = mx_get_ops(m->magic); } if ((m->magic == MUTT_UNKNOWN) || (m->magic == MUTT_MAILBOX_ERROR) || !m->mx_ops) { if (m->magic == MUTT_MAILBOX_ERROR) - mutt_perror(m->path); + mutt_perror(mutt_b2s(m->pathbuf)); else if ((m->magic == MUTT_UNKNOWN) || !m->mx_ops) - mutt_error(_("%s is not a mailbox"), m->path); + mutt_error(_("%s is not a mailbox"), mutt_b2s(m->pathbuf)); mx_fastclose_mailbox(m); ctx_free(&ctx); @@ -336,7 +336,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags) OptForceRefresh = true; if (!m->quiet) - mutt_message(_("Reading %s..."), m->path); + mutt_message(_("Reading %s..."), mutt_b2s(m->pathbuf)); int rc = m->mx_ops->mbox_open(ctx->mailbox); m->opened++; @@ -356,7 +356,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags) if (!m->quiet) mutt_clear_error(); if (rc == -2) - mutt_error(_("Reading from %s interrupted..."), m->path); + mutt_error(_("Reading from %s interrupted..."), mutt_b2s(m->pathbuf)); } else { @@ -424,14 +424,14 @@ static int sync_mailbox(struct Mailbox *m, int *index_hint) if (!m->quiet) { /* L10N: Displayed before/as a mailbox is being synced */ - mutt_message(_("Writing %s..."), m->path); + mutt_message(_("Writing %s..."), mutt_b2s(m->pathbuf)); } int rc = m->mx_ops->mbox_sync(m, index_hint); if ((rc != 0) && !m->quiet) { /* L10N: Displayed if a mailbox sync fails */ - mutt_error(_("Unable to write %s"), m->path); + mutt_error(_("Unable to write %s"), mutt_b2s(m->pathbuf)); } return rc; @@ -486,7 +486,7 @@ static int trash_append(struct Mailbox *m) return -1; } - if ((lstat(m->path, &stc) == 0) && (stc.st_ino == st.st_ino) && + if ((lstat(mutt_b2s(m->pathbuf), &stc) == 0) && (stc.st_ino == st.st_ino) && (stc.st_dev == st.st_dev) && (stc.st_rdev == st.st_rdev)) { return 0; /* we are in the trash folder: simple sync */ @@ -603,7 +603,7 @@ int mx_mbox_close(struct Context **ptr) if ((read_msgs != 0) && (C_Move != MUTT_NO)) { bool is_spool; - char *p = mutt_find_hook(MUTT_MBOX_HOOK, m->path); + char *p = mutt_find_hook(MUTT_MBOX_HOOK, mutt_b2s(m->pathbuf)); if (p) { is_spool = true; @@ -612,7 +612,7 @@ int mx_mbox_close(struct Context **ptr) else { mutt_str_strfcpy(mbox, C_Mbox, sizeof(mbox)); - is_spool = mutt_is_spool(m->path) && !mutt_is_spool(mbox); + is_spool = mutt_is_spool(mutt_b2s(m->pathbuf)) && !mutt_is_spool(mbox); } if (is_spool && (mbox[0] != '\0')) @@ -727,7 +727,8 @@ int mx_mbox_close(struct Context **ptr) } /* copy mails to the trash before expunging */ - if (purge && (m->msg_deleted != 0) && (mutt_str_strcmp(m->path, C_Trash) != 0)) + if (purge && (m->msg_deleted != 0) && + (mutt_str_strcmp(mutt_b2s(m->pathbuf), C_Trash) != 0)) { if (trash_append(ctx->mailbox) != 0) return -1; @@ -775,9 +776,9 @@ int mx_mbox_close(struct Context **ptr) if ((m->msg_count == m->msg_deleted) && ((m->magic == MUTT_MMDF) || (m->magic == MUTT_MBOX)) && - !mutt_is_spool(m->path) && !C_SaveEmpty) + !mutt_is_spool(mutt_b2s(m->pathbuf)) && !C_SaveEmpty) { - mutt_file_unlink_empty(m->path); + mutt_file_unlink_empty(mutt_b2s(m->pathbuf)); } #ifdef USE_SIDEBAR @@ -876,7 +877,8 @@ int mx_mbox_sync(struct Mailbox *m, int *index_hint) msgcount = m->msg_count; deleted = m->msg_deleted; - if (purge && (m->msg_deleted != 0) && (mutt_str_strcmp(m->path, C_Trash) != 0)) + if (purge && (m->msg_deleted != 0) && + (mutt_str_strcmp(mutt_b2s(m->pathbuf), C_Trash) != 0)) { if (trash_append(m) != 0) return -1; @@ -907,9 +909,9 @@ int mx_mbox_sync(struct Mailbox *m, int *index_hint) if ((m->msg_count == m->msg_deleted) && ((m->magic == MUTT_MBOX) || (m->magic == MUTT_MMDF)) && - !mutt_is_spool(m->path) && !C_SaveEmpty) + !mutt_is_spool(mutt_b2s(m->pathbuf)) && !C_SaveEmpty) { - unlink(m->path); + unlink(mutt_b2s(m->pathbuf)); mx_fastclose_mailbox(m); return 0; } @@ -1390,7 +1392,7 @@ int mx_path_canon2(struct Mailbox *m, const char *folder) if (m->realpath) mutt_str_strfcpy(buf, m->realpath, sizeof(buf)); else - mutt_str_strfcpy(buf, m->path, sizeof(buf)); + mutt_str_strfcpy(buf, mutt_b2s(m->pathbuf), sizeof(buf)); int rc = mx_path_canon(buf, sizeof(buf), folder, &m->magic); @@ -1399,7 +1401,7 @@ int mx_path_canon2(struct Mailbox *m, const char *folder) if (rc >= 0) { m->mx_ops = mx_get_ops(m->magic); - mutt_str_strfcpy(m->path, m->realpath, sizeof(m->path)); + mutt_buffer_strcpy(m->pathbuf, m->realpath); } return rc; @@ -1537,7 +1539,7 @@ struct Mailbox *mx_path_resolve(const char *path) m = mailbox_new(); m->flags = MB_HIDDEN; - mutt_str_strfcpy(m->path, path, sizeof(m->path)); + mutt_buffer_strcpy(m->pathbuf, path); mx_path_canon2(m, C_Folder); return m; diff --git a/nntp/nntp.c b/nntp/nntp.c index 54393fec6..ce8216928 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -2432,12 +2432,12 @@ static int nntp_mbox_open(struct Mailbox *m) void *hc = NULL; anum_t first, last, count = 0; - struct Url *url = url_parse(m->path); + struct Url *url = url_parse(mutt_b2s(m->pathbuf)); if (!url || !url->host || !url->path || !((url->scheme == U_NNTP) || (url->scheme == U_NNTPS))) { url_free(&url); - mutt_error(_("%s is an invalid newsgroup specification"), m->path); + mutt_error(_("%s is an invalid newsgroup specification"), mutt_b2s(m->pathbuf)); return -1; } diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 083ca530a..95de0cb39 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -93,7 +93,7 @@ char *C_NmRepliedTag; ///< Config: (notmuch) Tag to use for replied messages static header_cache_t *nm_hcache_open(struct Mailbox *m) { #ifdef USE_HCACHE - return mutt_hcache_open(C_HeaderCache, m->path, NULL); + return mutt_hcache_open(C_HeaderCache, mutt_b2s(m->pathbuf), NULL); #else return NULL; #endif @@ -307,7 +307,7 @@ static int init_mailbox(struct Mailbox *m) if (m->mdata) return 0; - m->mdata = nm_mdata_new(m->path); + m->mdata = nm_mdata_new(mutt_b2s(m->pathbuf)); if (!m->mdata) return -1; @@ -1926,10 +1926,10 @@ static int nm_mbox_check_stats(struct Mailbox *m, int flags) int limit = C_NmDbLimit; mutt_debug(LL_DEBUG1, "nm: count\n"); - url = url_parse(m->path); + url = url_parse(mutt_b2s(m->pathbuf)); if (!url) { - mutt_error(_("failed to parse notmuch uri: %s"), m->path); + mutt_error(_("failed to parse notmuch uri: %s"), mutt_b2s(m->pathbuf)); goto done; } @@ -2019,7 +2019,7 @@ int nm_description_to_path(const char *desc, char *buf, size_t buflen) if ((np->mailbox->magic == MUTT_NOTMUCH) && np->mailbox->desc && (strcmp(desc, np->mailbox->desc) == 0)) { - mutt_str_strfcpy(buf, np->mailbox->path, buflen); + mutt_str_strfcpy(buf, mutt_b2s(np->mailbox->pathbuf), buflen); buf[buflen - 1] = '\0'; return 0; } @@ -2372,7 +2372,7 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint) int rc = 0; struct Progress progress; - char *uri = mutt_str_strdup(m->path); + char *uri = mutt_str_strdup(mutt_b2s(m->pathbuf)); bool changed = false; char msgbuf[PATH_MAX + 64]; @@ -2381,7 +2381,7 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint) if (!m->quiet) { /* all is in this function so we don't use data->progress here */ - snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), m->path); + snprintf(msgbuf, sizeof(msgbuf), _("Writing %s..."), mutt_b2s(m->pathbuf)); mutt_progress_init(&progress, msgbuf, MUTT_PROGRESS_MSG, C_WriteInc, m->msg_count); } @@ -2408,10 +2408,10 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint) else email_get_fullpath(e, old, sizeof(old)); - mutt_str_strfcpy(m->path, edata->folder, sizeof(m->path)); + mutt_buffer_strcpy(m->pathbuf, edata->folder); m->magic = edata->magic; rc = mh_sync_mailbox_message(m, i, h); - mutt_str_strfcpy(m->path, uri, sizeof(m->path)); + mutt_buffer_strcpy(m->pathbuf, uri); m->magic = MUTT_NOTMUCH; if (rc) @@ -2431,7 +2431,7 @@ static int nm_mbox_sync(struct Mailbox *m, int *index_hint) FREE(&edata->oldpath); } - mutt_str_strfcpy(m->path, uri, sizeof(m->path)); + mutt_buffer_strcpy(m->pathbuf, uri); m->magic = MUTT_NOTMUCH; nm_db_release(m); diff --git a/pager.c b/pager.c index b3bb98a28..3d66b121f 100644 --- a/pager.c +++ b/pager.c @@ -2371,7 +2371,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P int check = mx_mbox_check(Context->mailbox, &index_hint); if (check < 0) { - if (!Context->mailbox || (Context->mailbox->path[0] == '\0')) + if (!Context->mailbox || mutt_buffer_is_empty(Context->mailbox->pathbuf)) { /* fatal error occurred */ ctx_free(&Context); diff --git a/pattern.c b/pattern.c index 8debfb43e..db05bd868 100644 --- a/pattern.c +++ b/pattern.c @@ -308,7 +308,7 @@ static bool eat_query(struct Pattern *pat, int flags, struct Buffer *s, struct B } else { - char *escaped_folder = mutt_path_escape(Context->mailbox->path); + char *escaped_folder = mutt_path_escape(mutt_b2s(Context->mailbox->pathbuf)); mutt_debug(LL_DEBUG2, "escaped folder path: %s\n", escaped_folder); mutt_buffer_addch(&cmd_buf, '\''); mutt_buffer_addstr(&cmd_buf, escaped_folder); diff --git a/pop/pop.c b/pop/pop.c index 94ef65d53..b52c9bb67 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -381,7 +381,7 @@ static int pop_fetch_headers(struct Mailbox *m) struct Progress progress; #ifdef USE_HCACHE - header_cache_t *hc = pop_hcache_open(adata, m->path); + header_cache_t *hc = pop_hcache_open(adata, mutt_b2s(m->pathbuf)); #endif time(&adata->check_time); @@ -785,7 +785,7 @@ int pop_ac_add(struct Account *a, struct Mailbox *m) a->adata = adata; a->free_adata = pop_adata_free; - struct Url *url = url_parse(m->path); + struct Url *url = url_parse(mutt_b2s(m->pathbuf)); if (url) { mutt_str_strfcpy(adata->conn_account.user, url->user, @@ -822,9 +822,9 @@ static int pop_mbox_open(struct Mailbox *m) struct ConnAccount acct = { { 0 } }; struct Url url; - if (pop_parse_path(m->path, &acct)) + if (pop_parse_path(mutt_b2s(m->pathbuf), &acct)) { - mutt_error(_("%s is an invalid POP path"), m->path); + mutt_error(_("%s is an invalid POP path"), mutt_b2s(m->pathbuf)); return -1; } @@ -832,8 +832,8 @@ static int pop_mbox_open(struct Mailbox *m) url.path = NULL; url_tostring(&url, buf, sizeof(buf), 0); - mutt_str_strfcpy(m->path, buf, sizeof(m->path)); - mutt_str_replace(&m->realpath, m->path); + mutt_buffer_strcpy(m->pathbuf, buf); + mutt_str_replace(&m->realpath, mutt_b2s(m->pathbuf)); struct PopAccountData *adata = m->account->adata; if (!adata) @@ -962,7 +962,7 @@ static int pop_mbox_sync(struct Mailbox *m, int *index_hint) MUTT_PROGRESS_MSG, C_WriteInc, num_deleted); #ifdef USE_HCACHE - hc = pop_hcache_open(adata, m->path); + hc = pop_hcache_open(adata, mutt_b2s(m->pathbuf)); #endif for (i = 0, j = 0, rc = 0; (rc == 0) && (i < m->msg_count); i++) @@ -1218,7 +1218,7 @@ static int pop_msg_save_hcache(struct Mailbox *m, struct Email *e) #ifdef USE_HCACHE struct PopAccountData *adata = pop_adata_get(m); struct PopEmailData *edata = e->edata; - header_cache_t *hc = pop_hcache_open(adata, m->path); + header_cache_t *hc = pop_hcache_open(adata, mutt_b2s(m->pathbuf)); rc = mutt_hcache_store(hc, edata->uid, strlen(edata->uid), e, 0); mutt_hcache_close(hc); #endif diff --git a/sidebar.c b/sidebar.c index 6af5cd504..d46b16698 100644 --- a/sidebar.c +++ b/sidebar.c @@ -258,8 +258,8 @@ static const char *sidebar_format_str(char *buf, size_t buflen, size_t col, int * mutt_expando_format to do the actual work. mutt_expando_format will callback to * us using sidebar_format_str() for the sidebar specific formatting characters. */ -static void make_sidebar_entry(char *buf, size_t buflen, int width, char *box, - struct SbEntry *sbe) +static void make_sidebar_entry(char *buf, size_t buflen, int width, + const char *box, struct SbEntry *sbe) { if (!buf || !box || !sbe) return; @@ -308,13 +308,13 @@ static int cb_qsort_sbe(const void *a, const void *b) { case SORT_COUNT: if (m2->msg_count == m1->msg_count) - rc = mutt_str_strcoll(m1->path, m2->path); + rc = mutt_str_strcoll(mutt_b2s(m1->pathbuf), mutt_b2s(m2->pathbuf)); else rc = (m2->msg_count - m1->msg_count); break; case SORT_UNREAD: if (m2->msg_unread == m1->msg_unread) - rc = mutt_str_strcoll(m1->path, m2->path); + rc = mutt_str_strcoll(mutt_b2s(m1->pathbuf), mutt_b2s(m2->pathbuf)); else rc = (m2->msg_unread - m1->msg_unread); break; @@ -323,15 +323,15 @@ static int cb_qsort_sbe(const void *a, const void *b) break; case SORT_FLAGGED: if (m2->msg_flagged == m1->msg_flagged) - rc = mutt_str_strcoll(m1->path, m2->path); + rc = mutt_str_strcoll(mutt_b2s(m1->pathbuf), mutt_b2s(m2->pathbuf)); else rc = (m2->msg_flagged - m1->msg_flagged); break; case SORT_PATH: { - rc = mutt_inbox_cmp(m1->path, m2->path); + rc = mutt_inbox_cmp(mutt_b2s(m1->pathbuf), mutt_b2s(m2->pathbuf)); if (rc == 0) - rc = mutt_str_strcoll(m1->path, m2->path); + rc = mutt_str_strcoll(mutt_b2s(m1->pathbuf), mutt_b2s(m2->pathbuf)); break; } } @@ -382,7 +382,7 @@ static void update_entries_visibility(void) continue; } - if (mutt_list_find(&SidebarWhitelist, sbe->mailbox->path) || + if (mutt_list_find(&SidebarWhitelist, mutt_b2s(sbe->mailbox->pathbuf)) || mutt_list_find(&SidebarWhitelist, sbe->mailbox->desc)) { /* Explicitly asked to be visible */ @@ -847,7 +847,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) else if (m->msg_flagged > 0) SET_COLOR(MT_COLOR_FLAGGED); else if ((ColorDefs[MT_COLOR_SB_SPOOLFILE] != 0) && - (mutt_str_strcmp(m->path, C_Spoolfile) == 0)) + (mutt_str_strcmp(mutt_b2s(m->pathbuf), C_Spoolfile) == 0)) { SET_COLOR(MT_COLOR_SB_SPOOLFILE); } @@ -880,20 +880,21 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) /* check whether C_Folder is a prefix of the current folder's path */ bool maildir_is_prefix = false; - if ((mutt_str_strlen(m->path) > maildirlen) && - (mutt_str_strncmp(C_Folder, m->path, maildirlen) == 0) && - C_SidebarDelimChars && strchr(C_SidebarDelimChars, m->path[maildirlen])) + if ((mutt_buffer_len(m->pathbuf) > maildirlen) && + (mutt_str_strncmp(C_Folder, mutt_b2s(m->pathbuf), maildirlen) == 0) && C_SidebarDelimChars && + strchr(C_SidebarDelimChars, mutt_b2s(m->pathbuf)[maildirlen])) { maildir_is_prefix = true; } /* calculate depth of current folder and generate its display name with indented spaces */ int sidebar_folder_depth = 0; - char *sidebar_folder_name = NULL; + const char *sidebar_folder_name; + struct Buffer *short_folder_name = NULL; if (C_SidebarShortPath) { /* disregard a trailing separator, so strlen() - 2 */ - sidebar_folder_name = m->path; + sidebar_folder_name = mutt_b2s(m->pathbuf); for (int i = mutt_str_strlen(sidebar_folder_name) - 2; i >= 0; i--) { if (C_SidebarDelimChars && strchr(C_SidebarDelimChars, sidebar_folder_name[i])) @@ -905,7 +906,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) } else if ((C_SidebarComponentDepth > 0) && C_SidebarDelimChars) { - sidebar_folder_name = m->path + maildir_is_prefix * (maildirlen + 1); + sidebar_folder_name = mutt_b2s(m->pathbuf) + maildir_is_prefix * (maildirlen + 1); for (int i = 0; i < C_SidebarComponentDepth; i++) { char *chars_after_delim = strpbrk(sidebar_folder_name, C_SidebarDelimChars); @@ -916,7 +917,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) } } else - sidebar_folder_name = m->path + maildir_is_prefix * (maildirlen + 1); + sidebar_folder_name = mutt_b2s(m->pathbuf) + maildir_is_prefix * (maildirlen + 1); if (m->desc) { @@ -925,7 +926,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) else if (maildir_is_prefix && C_SidebarFolderIndent) { int lastsep = 0; - const char *tmp_folder_name = m->path + maildirlen + 1; + const char *tmp_folder_name = mutt_b2s(m->pathbuf) + maildirlen + 1; int tmplen = (int) mutt_str_strlen(tmp_folder_name) - 1; for (int i = 0; i < tmplen; i++) { @@ -939,20 +940,17 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) { if (C_SidebarShortPath) tmp_folder_name += lastsep; /* basename */ - int sfn_len = mutt_str_strlen(tmp_folder_name) + - sidebar_folder_depth * mutt_str_strlen(C_SidebarIndentString) + 1; - sidebar_folder_name = mutt_mem_malloc(sfn_len); - sidebar_folder_name[0] = '\0'; + short_folder_name = mutt_buffer_pool_get(); for (int i = 0; i < sidebar_folder_depth; i++) - mutt_str_strcat(sidebar_folder_name, sfn_len, NONULL(C_SidebarIndentString)); - mutt_str_strcat(sidebar_folder_name, sfn_len, tmp_folder_name); + mutt_buffer_addstr(short_folder_name, NONULL(C_SidebarIndentString)); + mutt_buffer_addstr(short_folder_name, tmp_folder_name); + sidebar_folder_name = mutt_b2s(short_folder_name); } } char str[256]; make_sidebar_entry(str, sizeof(str), w, sidebar_folder_name, entry); printw("%s", str); - if (sidebar_folder_depth > 0) - FREE(&sidebar_folder_name); + mutt_buffer_pool_release(&short_folder_name); row++; } diff --git a/status.c b/status.c index 914072685..4aca4c5b8 100644 --- a/status.c +++ b/status.c @@ -149,9 +149,9 @@ static const char *status_format_str(char *buf, size_t buflen, size_t col, int c { mutt_str_strfcpy(tmp, m->desc, sizeof(tmp)); } - else if (m && (m->path[0] != '\0')) + else if (m && mutt_buffer_is_empty(m->pathbuf)) { - mutt_str_strfcpy(tmp, m->path, sizeof(tmp)); + mutt_str_strfcpy(tmp, mutt_b2s(m->pathbuf), sizeof(tmp)); mutt_pretty_mailbox(tmp, sizeof(tmp)); } else