From 3bc34894be2f45093f21f0ba1c10c42906c9ec27 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Tue, 30 Aug 2016 22:49:19 +0200 Subject: [PATCH] Replies possible with X-Original-To: header Adds a reply_with_xorig boolean parameter. When set, it allows to reply to emails using X-Original-To: header email address. This will work provided reverse_realname is not active or failed to find an appropriate From: to provide. The option, if fast_reply is disabled, also provides a From: prompt when hitting reply. By default it'll be filled with the extracted address. --- imap/message.c | 2 +- init.h | 10 ++++++++++ mutt.h | 2 ++ muttlib.c | 1 + parse.c | 6 ++++++ send.c | 25 +++++++++++++++++++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) diff --git a/imap/message.c b/imap/message.c index 8211d3a11..3e8b555d5 100644 --- a/imap/message.c +++ b/imap/message.c @@ -69,7 +69,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) int rc, mfhrc, oldmsgcount; int fetchlast = 0; int maxuid = 0; - static const char * const want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL X-KEYWORDS X-MOZILLA-KEYS KEYWORDS"; + static const char * const want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL X-KEYWORDS X-MOZILLA-KEYS KEYWORDS X-ORIGINAL-TO"; progress_t progress; int retval = -1; diff --git a/init.h b/init.h index dff4dd04b..f38abfa71 100644 --- a/init.h +++ b/init.h @@ -2762,6 +2762,16 @@ struct option_t MuttVars[] = { ** header field to the list address and you want to send a private ** message to the author of a message. */ + { "reply_with_xorig", DT_BOOL, R_NONE, OPTREPLYWITHXORIG, 0 }, + /* + ** .pp + ** This variable provides a toggle. When active, the From: header will be + ** extracted from the current mail's `X-Original-To:' header. This setting + ** does not have precedence over ``$reverse_realname''. + ** .pp + ** Assuming `fast_reply' is disabled, this option will prompt the user with a + ** prefilled From: header. + */ { "resolve", DT_BOOL, R_NONE, OPTRESOLVE, 1 }, /* ** .pp diff --git a/mutt.h b/mutt.h index e7ecdffdd..ea9f6287b 100644 --- a/mutt.h +++ b/mutt.h @@ -473,6 +473,7 @@ enum OPTREFLOWSPACEQUOTES, OPTREFLOWTEXT, OPTREPLYSELF, + OPTREPLYWITHXORIG, OPTRESOLVE, OPTRESUMEDRAFTFILES, OPTRESUMEEDITEDDRAFTFILES, @@ -678,6 +679,7 @@ typedef struct envelope ADDRESS *sender; ADDRESS *reply_to; ADDRESS *mail_followup_to; + ADDRESS *x_original_to; char *list_post; /* this stores a mailto URL, or nothing */ char *subject; char *real_subj; /* offset of the real subject */ diff --git a/muttlib.c b/muttlib.c index 41de6385a..067be7765 100644 --- a/muttlib.c +++ b/muttlib.c @@ -780,6 +780,7 @@ void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra) MOVE_ELEM(supersedes); MOVE_ELEM(date); MOVE_ELEM(labels); + MOVE_ELEM(x_original_to); if (!base->refs_changed) { MOVE_ELEM(references); diff --git a/parse.c b/parse.c index 2d5d8b910..92da61e36 100644 --- a/parse.c +++ b/parse.c @@ -1331,6 +1331,11 @@ int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, char *line, char *p, short matched = 1; } #endif + else if (!ascii_strcasecmp (line + 1, "-original-to")) + { + e->x_original_to = rfc822_parse_adrlist (e->x_original_to, p); + matched = 1; + } default: break; @@ -1548,6 +1553,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE *f, HEADER *hdr, short user_hdrs, rfc2047_decode_adrlist (e->mail_followup_to); rfc2047_decode_adrlist (e->return_path); rfc2047_decode_adrlist (e->sender); + rfc2047_decode_adrlist (e->x_original_to); if (e->subject) { diff --git a/send.c b/send.c index 007218fbb..61356eaf8 100644 --- a/send.c +++ b/send.c @@ -265,6 +265,10 @@ static int edit_envelope (ENVELOPE *en, int flags) return (-1); if (option (OPTASKBCC) && edit_address (&en->bcc, "Bcc: ") == -1) return (-1); + if (option (OPTREPLYWITHXORIG) && + (flags & (SENDREPLY|SENDLISTREPLY|SENDGROUPREPLY)) && + (edit_address (&en->from, "From: ") == -1)) + return (-1); } if (en->subject) @@ -1400,8 +1404,29 @@ ci_send_message (int flags, /* send mode */ * have their aliases expanded. */ + if (msg->env->from) + dprint (5, (debugfile, "ci_send_message: msg->env->from before set_reverse_name: %s\n", msg->env->from->mailbox)); msg->env->from = set_reverse_name (cur->env); } + if (cur && option (OPTREPLYWITHXORIG) && !(flags & (SENDPOSTPONED|SENDRESEND|SENDFORWARD))) + { + /* We shouldn't have to worry about freeing `msg->env->from' before + * setting it here since this code will only execute when doing some + * sort of reply. The pointer will only be set when using the -H command + * line option. + * + * If there is already a from address recorded in `msg->env->from', + * then it theoretically comes from OPTREVNAME handling, and we don't use + * the `X-Orig-To header'. + */ + if (cur->env->x_original_to && !msg->env->from) + { + msg->env->from = cur->env->x_original_to; + /* Not more than one from address */ + msg->env->from->next = NULL; + dprint (5, (debugfile, "ci_send_message: msg->env->from extracted from X-Original-To: header: %s\n", msg->env->from->mailbox)); + } + } if (! (flags & (SENDPOSTPONED|SENDRESEND)) && ! ((flags & SENDDRAFTFILE) && option (OPTRESUMEDRAFTFILES))) -- 2.40.0