From: Richard Russon Date: Sat, 1 Dec 2018 21:14:33 +0000 (+0000) Subject: more Context refactoring/protection X-Git-Tag: 2019-10-25~473 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0be3e27a959e39f900271a2950339fe62bfff579;p=neomutt more Context refactoring/protection --- diff --git a/commands.c b/commands.c index 98463376b..758dfc112 100644 --- a/commands.c +++ b/commands.c @@ -104,7 +104,7 @@ int mutt_display_message(struct Email *cur) snprintf(buf, sizeof(buf), "%s/%s", TYPE(cur->content), cur->content->subtype); mutt_parse_mime_message(Context->mailbox, cur); - mutt_message_hook(Context, cur, MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, cur, MUTT_MESSAGE_HOOK); /* see if crypto is needed for this message. if so, we should exit curses */ if ((WithCrypto != 0) && cur->security) @@ -445,13 +445,16 @@ static void pipe_msg(struct Email *e, FILE *fp, bool decode, bool print) static int pipe_message(struct Email *e, char *cmd, bool decode, bool print, bool split, const char *sep) { + if (!Context) + return 1; + int rc = 0; pid_t thepid; FILE *fpout = NULL; if (e) { - mutt_message_hook(Context, e, MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, e, MUTT_MESSAGE_HOOK); if ((WithCrypto != 0) && decode) { @@ -484,7 +487,7 @@ static int pipe_message(struct Email *e, char *cmd, bool decode, bool print, if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); mutt_parse_mime_message(Context->mailbox, Context->mailbox->hdrs[i]); if (Context->mailbox->hdrs[i]->security & ENCRYPT && !crypt_valid_passphrase(Context->mailbox->hdrs[i]->security)) @@ -501,7 +504,7 @@ static int pipe_message(struct Email *e, char *cmd, bool decode, bool print, if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); mutt_endwin(); thepid = mutt_create_filter(cmd, &fpout, NULL, NULL); if (thepid < 0) @@ -535,7 +538,7 @@ static int pipe_message(struct Email *e, char *cmd, bool decode, bool print, if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); pipe_msg(Context->mailbox->hdrs[i], fpout, decode, print); /* add the message separator */ if (sep) @@ -905,7 +908,7 @@ int mutt_save_message(struct Email *e, bool delete, bool decode, bool decrypt) need_passphrase = (e->security & ENCRYPT); app = e->security; } - mutt_message_hook(Context, e, MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, e, MUTT_MESSAGE_HOOK); mutt_default_save(buf, sizeof(buf), e); } else @@ -922,7 +925,7 @@ int mutt_save_message(struct Email *e, bool delete, bool decode, bool decrypt) if (e) { - mutt_message_hook(Context, e, MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, e, MUTT_MESSAGE_HOOK); mutt_default_save(buf, sizeof(buf), e); if (WithCrypto) { @@ -1037,7 +1040,7 @@ int mutt_save_message(struct Email *e, bool delete, bool decode, bool decrypt) if (!message_is_tagged(Context, i)) continue; - mutt_message_hook(Context, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); + mutt_message_hook(Context->mailbox, Context->mailbox->hdrs[i], MUTT_MESSAGE_HOOK); rc = mutt_save_message_ctx(Context->mailbox->hdrs[i], delete, decode, decrypt, savectx->mailbox); if (rc != 0) diff --git a/hook.c b/hook.c index b60301920..743189e93 100644 --- a/hook.c +++ b/hook.c @@ -431,11 +431,11 @@ char *mutt_find_hook(int type, const char *pat) /** * mutt_message_hook - Perform a message hook - * @param ctx Mailbox Context + * @param m Mailbox Context * @param e Email * @param type Hook type, e.g. #MUTT_MESSAGE_HOOK */ -void mutt_message_hook(struct Context *ctx, struct Email *e, int type) +void mutt_message_hook(struct Mailbox *m, struct Email *e, int type) { struct Buffer err, token; struct Hook *hook = NULL; @@ -454,7 +454,7 @@ void mutt_message_hook(struct Context *ctx, struct Email *e, int type) if (hook->type & type) { - if ((mutt_pattern_exec(hook->pattern, 0, ctx->mailbox, e, &cache) > 0) ^ + if ((mutt_pattern_exec(hook->pattern, 0, m, e, &cache) > 0) ^ hook->regex.not) { if (mutt_parse_rc_line(hook->command, &token, &err) == -1) diff --git a/hook.h b/hook.h index 10a65ecd6..c60e4e29e 100644 --- a/hook.h +++ b/hook.h @@ -28,9 +28,9 @@ struct Address; struct Buffer; -struct Context; struct Email; struct ListHead; +struct Mailbox; /* These Config Variables are only used in hook.c */ extern char *DefaultHook; @@ -66,7 +66,7 @@ void mutt_default_save(char *path, size_t pathlen, struct Email *e); void mutt_delete_hooks(int type); char *mutt_find_hook(int type, const char *pat); void mutt_folder_hook(const char *path); -void mutt_message_hook(struct Context *ctx, struct Email *e, int type); +void mutt_message_hook(struct Mailbox *m, struct Email *e, int type); int mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err); int mutt_parse_unhook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err); void mutt_select_fcc(char *path, size_t pathlen, struct Email *e); diff --git a/recvattach.c b/recvattach.c index b0ee39953..15c94a684 100644 --- a/recvattach.c +++ b/recvattach.c @@ -74,7 +74,7 @@ static void mutt_update_recvattach_menu(struct AttachCtx *actx, struct Menu *men static const char *Mailbox_is_read_only = N_("Mailbox is read-only"); #define CHECK_READONLY \ - if (Context->mailbox->readonly) \ + if (!Context || !Context->mailbox || Context->mailbox->readonly) \ { \ mutt_flushinp(); \ mutt_error(_(Mailbox_is_read_only)); \ @@ -1306,12 +1306,14 @@ void mutt_view_attachments(struct Email *e) int flags = 0; int op = OP_NULL; + struct Mailbox *m = Context ? Context->mailbox : NULL; + /* make sure we have parsed this message */ - mutt_parse_mime_message(Context->mailbox, e); + mutt_parse_mime_message(m, e); - mutt_message_hook(Context, e, MUTT_MESSAGE_HOOK); + mutt_message_hook(m, e, MUTT_MESSAGE_HOOK); - struct Message *msg = mx_msg_open(Context->mailbox, e->msgno); + struct Message *msg = mx_msg_open(m, e->msgno); if (!msg) return; @@ -1406,7 +1408,7 @@ void mutt_view_attachments(struct Email *e) CHECK_READONLY; #ifdef USE_POP - if (Context->mailbox->magic == MUTT_POP) + if (m->magic == MUTT_POP) { mutt_flushinp(); mutt_error(_("Can't delete attachment from POP server")); @@ -1415,7 +1417,7 @@ void mutt_view_attachments(struct Email *e) #endif #ifdef USE_NNTP - if (Context->mailbox->magic == MUTT_NNTP) + if (m->magic == MUTT_NNTP) { mutt_flushinp(); mutt_error(_("Can't delete attachment from news server")); @@ -1571,7 +1573,7 @@ void mutt_view_attachments(struct Email *e) break; case OP_EXIT: - mx_msg_close(Context->mailbox, &msg); + mx_msg_close(m, &msg); e->attach_del = false; for (int i = 0; i < actx->idxlen; i++) diff --git a/send.c b/send.c index 04072576c..0634cf94f 100644 --- a/send.c +++ b/send.c @@ -538,7 +538,7 @@ static int include_forward(struct Context *ctx, struct Email *cur, FILE *out) int chflags = CH_DECODE, cmflags = 0; mutt_parse_mime_message(ctx->mailbox, cur); - mutt_message_hook(ctx, cur, MUTT_MESSAGE_HOOK); + mutt_message_hook(ctx->mailbox, cur, MUTT_MESSAGE_HOOK); if ((WithCrypto != 0) && (cur->security & ENCRYPT) && ForwardDecode) { @@ -627,7 +627,7 @@ static int include_reply(struct Context *ctx, struct Email *cur, FILE *out) } mutt_parse_mime_message(ctx->mailbox, cur); - mutt_message_hook(ctx, cur, MUTT_MESSAGE_HOOK); + mutt_message_hook(ctx->mailbox, cur, MUTT_MESSAGE_HOOK); mutt_make_attribution(ctx, cur, out); @@ -1757,7 +1757,7 @@ int ci_send_message(int flags, struct Email *msg, char *tempfile, if ((flags & SEND_REPLY) && cur) { /* change setting based upon message we are replying to */ - mutt_message_hook(ctx, cur, MUTT_REPLY_HOOK); + mutt_message_hook(ctx->mailbox, cur, MUTT_REPLY_HOOK); /* set the replied flag for the message we are generating so that the * user can use ~Q in a send-hook to know when reply-hook's are also