On 2021-11-22 12:33 -0600, Aaron Poffenberger <a...@hypernote.com> wrote:
> On 2021-11-22 12:18 -0600, Aaron Poffenberger <a...@hypernote.com> wrote:
> > 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.
> > 
> > > 
> 
> Here's a revised version of the patch.
> 
> I forgot to set fmt back to "<%z@%f>" in the messageid.c, and the
> from_fqdn variable wasn't sorted correctly with the others in the
> function.
> 

My sincere apologies for sending yet another fix.

When I rewrote the patch to put strchr on its own, I forgot to add "+
1" when using it. :(

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..d5c788ae 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,16 +108,21 @@ 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 *from_fqdn;
   char *rv;
 
   id_data.now = time (NULL);
@@ -124,6 +130,22 @@ 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
+  {
+    from_fqdn = strchr (from, '@');
+    if (from_fqdn)
+      id_data.from_fqdn = from_fqdn + 1;
+    else
+      id_data.from_fqdn = from;
+  }
+
   fmt = MessageIdFormat;
   if (!fmt)
     fmt = "<%z@%f>";
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);

Reply via email to