On 2021-11-22 10:02 -0800, Kevin J. McCarthy <ke...@8t8.us> wrote: > On Mon, Nov 22, 2021 at 10:09:16AM -0600, Aaron Poffenberger wrote: > > Lastly, the patch updates the documentation and changes the default > > message_id_format from "<%z@%f>", to "<%z@%F>" so that Message-IDs are > > always generated using the fqdn of the From address. > > I'm against changing the default. The behavior you're describing by AT&T is > insane, and I don't believe Mutt's LHS randomization is strong enough to > support the from address domain by default.
Fair enough. Just having the option to use %F is enough for me. The attached patch removes that change. > > > diff --git a/messageid.c b/messageid.c > > index e4ac4410..2ab63288 100644 > > --- a/messageid.c > > +++ b/messageid.c > > @@ -30,6 +30,7 @@ typedef struct msg_id_data > > time_t now; > > struct tm tm; > > const char *fqdn; > > + const char *from_fqdn; > > } MSG_ID_DATA; > > > > -char *mutt_gen_msgid (void) > > +char *mutt_gen_msgid (const char *from) > > { > > MSG_ID_DATA id_data; > > BUFFER *buf, *tmp; > > @@ -124,9 +129,17 @@ char *mutt_gen_msgid (void) > > if (!(id_data.fqdn = mutt_fqdn(0))) > > id_data.fqdn = NONULL(Hostname); > > > > + /* from should be a fully-formatted email address, > > + * nevertheless, handle cases where the caller > > + * sends just the fqdn or NULL. */ > > + if (!from) > > + id_data.from_fqdn = id_data.fqdn; > > + else if (!(id_data.from_fqdn = strchr (from, '@') + 1)) > > If there is no '@' in from, it looks like id_data.from_fqdn would have value > (NULL + 1). > > > + id_data.from_fqdn = from; > > + I tried to avoid that. The attached patch breaks out strchr from the test. > > -- > Kevin J. McCarthy > GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA Cheers, --Aaron diff --git a/init.h b/init.h index 0d920fcd..43374fdd 100644 --- a/init.h +++ b/init.h @@ -2210,6 +2210,7 @@ struct option_t MuttVars[] = { ** .dt %c .dd step counter looping from ``A'' to ``Z'' ** .dt %d .dd current day of the month (GMT) ** .dt %f .dd $$hostname + ** .dt %F .dd From hostname (after @ in from address) ** .dt %H .dd current hour using a 24-hour clock (GMT) ** .dt %m .dd current month number (GMT) ** .dt %M .dd current minute of the hour (GMT) diff --git a/messageid.c b/messageid.c index e4ac4410..72b56ce4 100644 --- a/messageid.c +++ b/messageid.c @@ -30,6 +30,7 @@ typedef struct msg_id_data time_t now; struct tm tm; const char *fqdn; + const char *from_fqdn; } MSG_ID_DATA; static const char *id_format_str (char *dest, size_t destlen, size_t col, @@ -107,26 +108,47 @@ static const char *id_format_str (char *dest, size_t destlen, size_t col, case 'f': mutt_format_s (dest, destlen, fmt, id_data->fqdn); break; + + case 'F': + mutt_format_s (dest, destlen, fmt, id_data->from_fqdn); + break; } return (src); } -char *mutt_gen_msgid (void) +char *mutt_gen_msgid (const char *from) { MSG_ID_DATA id_data; BUFFER *buf, *tmp; const char *fmt; char *rv; + char *from_fqdn; id_data.now = time (NULL); memcpy (&id_data.tm, gmtime (&id_data.now), sizeof(id_data.tm)); if (!(id_data.fqdn = mutt_fqdn(0))) id_data.fqdn = NONULL(Hostname); + /* from should be a fully-formatted email address, + * nevertheless, handle cases where the caller + * sends just the fqdn or NULL. */ + if (!from) + { + id_data.from_fqdn = id_data.fqdn; + } + else + { + from_fqdn = strchr (from, '@'); + if (from_fqdn) + id_data.from_fqdn = from_fqdn; + else + id_data.from_fqdn = from; + } + fmt = MessageIdFormat; if (!fmt) - fmt = "<%z@%f>"; + fmt = "<%z@%F>"; buf = mutt_buffer_pool_get (); mutt_FormatString (buf->data, buf->dsize, 0, buf->dsize, diff --git a/protos.h b/protos.h index fae28c99..f85e1862 100644 --- a/protos.h +++ b/protos.h @@ -151,7 +151,7 @@ void mutt_buffer_expand_multi_path_norel (BUFFER *src, const char *delimiter); void mutt_buffer_remove_path_password (BUFFER *dest, const char *src); char *mutt_find_hook (int, const char *); char *mutt_gecos_name (char *, size_t, struct passwd *); -char *mutt_gen_msgid (void); +char *mutt_gen_msgid (const char *); char *mutt_get_body_charset (char *, size_t, BODY *); const char *mutt_get_name (ADDRESS *); char *mutt_get_parameter (const char *, PARAMETER *); diff --git a/sendlib.c b/sendlib.c index 72f86e68..6334a3aa 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2845,7 +2845,7 @@ void mutt_prepare_envelope (ENVELOPE *env, int final) mutt_set_followup_to (env); if (!env->message_id) - env->message_id = mutt_gen_msgid (); + env->message_id = mutt_gen_msgid (env->from->mailbox); } /* Take care of 8-bit => 7-bit conversion. */ @@ -2908,7 +2908,7 @@ static int _mutt_bounce_message (FILE *fp, HEADER *h, ADDRESS *to, const char *r fprintf (f, "Resent-Date: %s\n", mutt_b2s (date)); mutt_buffer_pool_release (&date); - msgid_str = mutt_gen_msgid(); + msgid_str = mutt_gen_msgid(resent_from); fprintf (f, "Resent-Message-ID: %s\n", msgid_str); fputs ("Resent-To: ", f); mutt_write_address_list (to, f, 11, 0);