From c5d770ead5cd8444859dd4a785677aa1920454f0 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 24 Oct 2019 14:46:06 +0800 Subject: [PATCH] Convert fcc to a buffer. This affects the send.c flow (ci_send_message()), the compose menu, and various helper functions. --- compose.c | 23 +++++++++++------------ edit.c | 2 +- headers.c | 7 +++---- hook.c | 19 ++++++++++++------- postpone.c | 7 +++---- protos.h | 10 +++++----- send.c | 48 +++++++++++++++++++++++++++++------------------- sendlib.c | 2 +- 8 files changed, 65 insertions(+), 53 deletions(-) diff --git a/compose.c b/compose.c index c0a3f6d0..cff4e294 100644 --- a/compose.c +++ b/compose.c @@ -171,7 +171,7 @@ static const char *AutocryptRecUiFlags[] = { typedef struct { HEADER *msg; - char *fcc; + BUFFER *fcc; #ifdef USE_AUTOCRYPT autocrypt_rec_t autocrypt_rec; int autocrypt_rec_override; @@ -545,7 +545,7 @@ static void draw_envelope_addr (int line, ADDRESS *addr) static void draw_envelope (compose_redraw_data_t *rd) { HEADER *msg = rd->msg; - char *fcc = rd->fcc; + const char *fcc = mutt_b2s (rd->fcc); draw_envelope_addr (HDR_FROM, msg->env->from); draw_envelope_addr (HDR_TO, msg->env->to); @@ -891,8 +891,7 @@ static void compose_menu_redraw (MUTTMENU *menu) * -1 abort message */ int mutt_compose_menu (HEADER *msg, /* structure for new message */ - char *fcc, /* where to save a copy of the message */ - size_t fcclen, + BUFFER *fcc, /* where to save a copy of the message */ HEADER *cur, /* current message */ int flags) { @@ -982,13 +981,13 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); break; case OP_COMPOSE_EDIT_FCC: - strfcpy (buf, fcc, sizeof (buf)); - if (mutt_get_field (_("Fcc: "), buf, sizeof (buf), MUTT_FILE | MUTT_CLEAR) == 0) + mutt_buffer_strcpy (fname, mutt_b2s (fcc)); + if (mutt_buffer_get_field (_("Fcc: "), fname, MUTT_FILE | MUTT_CLEAR) == 0) { - strfcpy (fcc, buf, fcclen); - mutt_pretty_mailbox (fcc, fcclen); + mutt_buffer_strcpy (fcc, mutt_b2s (fname)); + mutt_buffer_pretty_mailbox (fcc); mutt_window_move (MuttIndexWindow, HDR_FCC, HDR_XOFFSET); - mutt_paddstr (W, fcc); + mutt_paddstr (W, mutt_b2s (fcc)); fccSet = 1; } mutt_message_hook (NULL, msg, MUTT_SEND2HOOK); @@ -1015,7 +1014,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ char *tag = NULL, *err = NULL; mutt_env_to_local (msg->env); mutt_edit_headers (NONULL (Editor), msg->content->filename, msg, - fcc, fcclen); + fcc); if (mutt_env_to_intl (msg->env, &tag, &err)) { mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err); @@ -1333,13 +1332,13 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ break; #endif - if (!fccSet && *fcc) + if (!fccSet && mutt_buffer_len (fcc)) { if ((i = query_quadoption (OPT_COPY, _("Save a copy of this message?"))) == -1) break; else if (i == MUTT_NO) - *fcc = 0; + mutt_buffer_clear (fcc); } loop = 0; diff --git a/edit.c b/edit.c index 2a34699c..fbb99822 100644 --- a/edit.c +++ b/edit.c @@ -450,7 +450,7 @@ int mutt_builtin_editor (const char *path, HEADER *msg, HEADER *cur) if (option (OPTEDITHDRS)) { mutt_env_to_local (msg->env); - mutt_edit_headers (NONULL(Visual), path, msg, NULL, 0); + mutt_edit_headers (NONULL(Visual), path, msg, NULL); if (mutt_env_to_intl (msg->env, &tag, &err)) printw (_("Bad IDN in %s: '%s'\n"), tag, err); } diff --git a/headers.c b/headers.c index fecaa991..b1a82cae 100644 --- a/headers.c +++ b/headers.c @@ -32,8 +32,7 @@ void mutt_edit_headers (const char *editor, const char *body, HEADER *msg, - char *fcc, - size_t fcclen) + BUFFER *fcc) { BUFFER *path = NULL; /* tempfile used to edit headers + body */ char buffer[LONG_STRING]; @@ -146,8 +145,8 @@ void mutt_edit_headers (const char *editor, p = skip_email_wsp(cur->data + 4); if (*p) { - strfcpy (fcc, p, fcclen); - mutt_pretty_mailbox (fcc, fcclen); + mutt_buffer_strcpy (fcc, p); + mutt_buffer_pretty_mailbox (fcc); } keep = 0; } diff --git a/hook.c b/hook.c index 137a5616..dc70c958 100644 --- a/hook.c +++ b/hook.c @@ -570,13 +570,15 @@ void mutt_default_save (char *path, size_t pathlen, HEADER *hdr) } } -void mutt_select_fcc (char *path, size_t pathlen, HEADER *hdr) +void mutt_select_fcc (BUFFER *path, HEADER *hdr) { ADDRESS *adr; BUFFER *buf = NULL; ENVELOPE *env = hdr->env; - if (mutt_addr_hook (path, pathlen, MUTT_FCCHOOK, NULL, hdr) != 0) + mutt_buffer_increase_size (path, _POSIX_PATH_MAX); + + if (mutt_addr_hook (path->data, path->dsize, MUTT_FCCHOOK, NULL, hdr) != 0) { if ((option (OPTSAVENAME) || option (OPTFORCENAME)) && (env->to || env->cc || env->bcc)) @@ -584,15 +586,18 @@ void mutt_select_fcc (char *path, size_t pathlen, HEADER *hdr) adr = env->to ? env->to : (env->cc ? env->cc : env->bcc); buf = mutt_buffer_pool_get (); mutt_safe_path (buf, adr); - mutt_concat_path (path, NONULL(Maildir), mutt_b2s (buf), pathlen); + mutt_buffer_concat_path (path, NONULL(Maildir), mutt_b2s (buf)); mutt_buffer_pool_release (&buf); - if (!option (OPTFORCENAME) && mx_access (path, W_OK) != 0) - strfcpy (path, NONULL (Outbox), pathlen); + if (!option (OPTFORCENAME) && mx_access (mutt_b2s (path), W_OK) != 0) + mutt_buffer_strcpy (path, NONULL (Outbox)); } else - strfcpy (path, NONULL (Outbox), pathlen); + mutt_buffer_strcpy (path, NONULL (Outbox)); } - mutt_pretty_mailbox (path, pathlen); + else + mutt_buffer_fix_dptr (path); + + mutt_buffer_pretty_mailbox (path); } static char *_mutt_string_hook (const char *match, int hook) diff --git a/postpone.c b/postpone.c index edad66c4..790cde48 100644 --- a/postpone.c +++ b/postpone.c @@ -227,14 +227,13 @@ static HEADER *select_msg (void) * cur if message was a reply, `cur' is set to the message which * `hdr' is in reply to * fcc fcc for the recalled message - * fcclen max length of fcc * * return vals: * -1 error/no messages * 0 normal exit * SENDREPLY recalled message is a reply */ -int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size_t fcclen) +int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, BUFFER *fcc) { HEADER *h; int code = SENDPOSTPONED; @@ -326,8 +325,8 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size else if (ascii_strncasecmp ("X-Mutt-Fcc:", tmp->data, 11) == 0) { p = skip_email_wsp(tmp->data + 11); - strfcpy (fcc, p, fcclen); - mutt_pretty_mailbox (fcc, fcclen); + mutt_buffer_strcpy (fcc, p); + mutt_buffer_pretty_mailbox (fcc); /* remove the X-Mutt-Fcc: header field */ next = tmp->next; diff --git a/protos.h b/protos.h index 759acc4f..e2f033b1 100644 --- a/protos.h +++ b/protos.h @@ -194,7 +194,7 @@ void mutt_display_address (ENVELOPE *); void mutt_display_sanitize (char *); int mutt_edit_content_type (HEADER *, BODY *, FILE *); void mutt_edit_file (const char *, const char *); -void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t); +void mutt_edit_headers (const char *, const char *, HEADER *, BUFFER *); char **mutt_envlist (void); void mutt_envlist_set (const char *name, const char *value, int overwrite); int mutt_filter_unprintable (char **); @@ -270,7 +270,7 @@ int mutt_rx_sanitize_string (BUFFER *dest, const char *src); void mutt_save_path (char *s, size_t l, ADDRESS *a); void mutt_buffer_save_path (BUFFER *dest, ADDRESS *a); void mutt_score_message (CONTEXT *, HEADER *, int); -void mutt_select_fcc (char *, size_t, HEADER *); +void mutt_select_fcc (BUFFER *, HEADER *); #define mutt_select_file(A,B,C) _mutt_select_file(A,B,C,NULL,NULL) void _mutt_select_file (char *, size_t, int, char ***, int *); #define mutt_buffer_select_file(A,B) _mutt_buffer_select_file(A,B,NULL,NULL) @@ -345,7 +345,7 @@ int _mutt_buffer_get_field (const char *, BUFFER *, int, int, char ***, int *); int mutt_get_hook_type (const char *); int mutt_get_field_unbuffered (char *, char *, size_t, int); #define mutt_get_password(A,B,C) mutt_get_field_unbuffered(A,B,C,MUTT_PASS) -int mutt_get_postponed (CONTEXT *, HEADER *, HEADER **, char *, size_t); +int mutt_get_postponed (CONTEXT *, HEADER *, HEADER **, BUFFER *); int mutt_get_tmp_attachment (BODY *); int mutt_index_menu (void); int mutt_invoke_sendmail (ADDRESS *, ADDRESS *, ADDRESS *, ADDRESS *, const char *, int); @@ -398,14 +398,14 @@ int mutt_smtp_send (const ADDRESS *, const ADDRESS *, const ADDRESS *, size_t mutt_wstr_trunc (const char *, size_t, size_t, size_t *); int mutt_charlen (const char *s, int *); int mutt_strwidth (const char *); -int mutt_compose_menu (HEADER *, char *, size_t, HEADER *, int); +int mutt_compose_menu (HEADER *, BUFFER *, HEADER *, int); int mutt_thread_set_flag (HEADER *, int, int, int); int mutt_user_is_recipient (HEADER *); void mutt_update_num_postponed (void); int mutt_wait_filter (pid_t); int mutt_wait_interactive_filter (pid_t); int mutt_which_case (const char *); -int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char *); +int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, const char *); int mutt_write_mime_body (BODY *, FILE *); int mutt_write_mime_header (BODY *, FILE *); int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, int flags); diff --git a/send.c b/send.c index 18771614..4379a35f 100644 --- a/send.c +++ b/send.c @@ -1173,7 +1173,7 @@ cleanup: return (i); } -static int save_fcc (HEADER *msg, char *fcc, size_t fcc_len, +static int save_fcc (HEADER *msg, BUFFER *fcc, BODY *clear_content, char *pgpkeylist, int flags) { @@ -1184,7 +1184,7 @@ static int save_fcc (HEADER *msg, char *fcc, size_t fcc_len, BODY *save_parts = NULL; int choice; - mutt_expand_path (fcc, fcc_len); + mutt_buffer_expand_path (fcc); /* Don't save a copy when we are in batch-mode, and the FCC * folder is on an IMAP server: This would involve possibly lots @@ -1196,14 +1196,17 @@ static int save_fcc (HEADER *msg, char *fcc, size_t fcc_len, */ #ifdef USE_IMAP - if ((flags & SENDBATCH) && fcc[0] && mx_is_imap (fcc)) + if ((flags & SENDBATCH) && + mutt_buffer_len (fcc) && + mx_is_imap (mutt_b2s (fcc))) { mutt_error _ ("Fcc to an IMAP mailbox is not supported in batch mode"); return rc; } #endif - if (!(*fcc && mutt_strcmp ("/dev/null", fcc))) + if (!(mutt_buffer_len (fcc) && + mutt_strcmp ("/dev/null", mutt_b2s (fcc)))) return rc; /* Before sending, we don't allow message manipulation because it @@ -1267,7 +1270,7 @@ full_fcc: * message was first postponed. */ msg->received = time (NULL); - rc = mutt_write_fcc (fcc, msg, NULL, 0, NULL); + rc = mutt_write_fcc (mutt_b2s (fcc), msg, NULL, 0, NULL); while (rc && !(flags & SENDBATCH)) { mutt_clear_error (); @@ -1292,8 +1295,8 @@ full_fcc: This is the prompt to enter an "alternate (m)ailbox" when the initial Fcc fails. */ - rc = mutt_enter_fname (_("Fcc mailbox"), fcc, fcc_len, 1); - if ((rc == -1) || !fcc[0]) + rc = mutt_buffer_enter_fname (_("Fcc mailbox"), fcc, 1); + if ((rc == -1) || !mutt_buffer_len (fcc)) { rc = 0; break; @@ -1301,7 +1304,7 @@ full_fcc: /* fall through */ case 1: /* (r)etry */ - rc = mutt_write_fcc (fcc, msg, NULL, 0, NULL); + rc = mutt_write_fcc (mutt_b2s (fcc), msg, NULL, 0, NULL); break; case -1: /* abort */ @@ -1463,7 +1466,7 @@ static int has_attach_keyword (char *filename) return match; } -static int postpone_message (HEADER *msg, HEADER *cur, char *fcc, int flags) +static int postpone_message (HEADER *msg, HEADER *cur, const char *fcc, int flags) { char *pgpkeylist = NULL; char *encrypt_as = NULL; @@ -1566,7 +1569,7 @@ ci_send_message (int flags, /* send mode */ HEADER *cur) /* current message */ { char buffer[LONG_STRING]; - char fcc[_POSIX_PATH_MAX] = ""; /* where to copy this message */ + BUFFER *fcc; /* where to copy this message */ FILE *tempfp = NULL; BODY *pbody; int i, killfrom = 0; @@ -1595,6 +1598,10 @@ ci_send_message (int flags, /* send mode */ flags |= SENDPOSTPONED; } + /* Allocate the buffer due to the long lifetime, but + * pre-resize it to ensure there are no NULL data field issues */ + fcc = mutt_buffer_new (); + mutt_buffer_increase_size (fcc, LONG_STRING); if (flags & SENDPOSTPONED) { @@ -1615,7 +1622,7 @@ ci_send_message (int flags, /* send mode */ if (flags == SENDPOSTPONED) { - if ((flags = mutt_get_postponed (ctx, msg, &cur, fcc, sizeof (fcc))) < 0) + if ((flags = mutt_get_postponed (ctx, msg, &cur, fcc)) < 0) { flags = SENDPOSTPONED; goto cleanup; @@ -1861,7 +1868,7 @@ ci_send_message (int flags, /* send mode */ else if (option (OPTEDITHDRS)) { mutt_env_to_local (msg->env); - mutt_edit_headers (Editor, msg->content->filename, msg, fcc, sizeof (fcc)); + mutt_edit_headers (Editor, msg->content->filename, msg, fcc); mutt_env_to_intl (msg->env, NULL, NULL); } else @@ -2013,7 +2020,9 @@ ci_send_message (int flags, /* send mode */ /* specify a default fcc. if we are in batchmode, only save a copy of * the message if the value of $copy is yes or ask-yes */ - if (!fcc[0] && !(flags & (SENDPOSTPONEDFCC)) && (!(flags & SENDBATCH) || (quadoption (OPT_COPY) & 0x1))) + if (!mutt_buffer_len (fcc) && + !(flags & (SENDPOSTPONEDFCC)) && + (!(flags & SENDBATCH) || (quadoption (OPT_COPY) & 0x1))) { /* set the default FCC */ if (!msg->env->from) @@ -2022,7 +2031,7 @@ ci_send_message (int flags, /* send mode */ killfrom = 1; /* no need to check $use_from because if the user specified a from address it would have already been set by now */ } - mutt_select_fcc (fcc, sizeof (fcc), msg); + mutt_select_fcc (fcc, msg); if (killfrom) { rfc822_free_address (&msg->env->from); @@ -2039,8 +2048,8 @@ ci_send_message (int flags, /* send mode */ { main_loop: - mutt_pretty_mailbox (fcc, sizeof (fcc)); - i = mutt_compose_menu (msg, fcc, sizeof (fcc), cur, + mutt_buffer_pretty_mailbox (fcc); + i = mutt_compose_menu (msg, fcc, cur, (flags & SENDNOFREEHEADER ? MUTT_COMPOSE_NOFREEHEADER : 0)); if (i == -1) { @@ -2050,7 +2059,7 @@ main_loop: } else if (i == 1) { - if (postpone_message (msg, cur, fcc, flags) != 0) + if (postpone_message (msg, cur, mutt_b2s (fcc), flags) != 0) goto main_loop; mutt_message _("Message postponed."); rv = 1; @@ -2173,7 +2182,7 @@ main_loop: mutt_prepare_envelope (msg->env, 1); if (option (OPTFCCBEFORESEND)) - save_fcc (msg, fcc, sizeof(fcc), clear_content, pgpkeylist, flags); + save_fcc (msg, fcc, clear_content, pgpkeylist, flags); if ((i = send_message (msg)) < 0) { @@ -2209,7 +2218,7 @@ main_loop: } if (!option (OPTFCCBEFORESEND)) - save_fcc (msg, fcc, sizeof(fcc), clear_content, pgpkeylist, flags); + save_fcc (msg, fcc, clear_content, pgpkeylist, flags); if (!option (OPTNOCURSES) && ! (flags & SENDMAILX)) { @@ -2243,6 +2252,7 @@ main_loop: rv = 0; cleanup: + mutt_buffer_free (&fcc); if (flags & SENDPOSTPONED) { diff --git a/sendlib.c b/sendlib.c index 24ef35aa..72ac3a93 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2784,7 +2784,7 @@ static void set_noconv_flags (BODY *b, short flag) } } -int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, char *fcc) +int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, const char *fcc) { CONTEXT f; MESSAGE *msg; -- 2.40.0