I felt hacking custom scripts to add the In-Reply-To header in a reply
is a bad solution if there's no reason we can't just make mail do it
automagically.  So, here comes the diff.

There are a few additional changes here:
  - Names starting with underscores are reserved, so I gave
    _respond and _Respond names which also document their
    behavior a little better.  Now they're replyall and
    replyorig.
  - Ansify replyall
  - Fix up whitespace in a couple relevant places.

If someone insists, I might look into adding a knob, though I don't
really see why anyone should want to turn this behavior off.


Index: src/usr.bin/mail//cmd3.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/cmd3.c,v
retrieving revision 1.25
diff -u -p -r1.25 cmd3.c
--- src/usr.bin/mail//cmd3.c    6 Apr 2011 11:36:26 -0000       1.25
+++ src/usr.bin/mail//cmd3.c    26 Jul 2011 13:15:26 -0000
@@ -176,9 +176,9 @@ respond(void *v)
        int *msgvec = v;
 
        if (value("Replyall") == NULL)
-               return(_respond(msgvec));
+               return(replyall(msgvec));
        else
-               return(_Respond(msgvec));
+               return(replyorig(msgvec));
 }
 
 /*
@@ -186,8 +186,7 @@ respond(void *v)
  * message header and send them off to mail1()
  */
 int
-_respond(msgvec)
-       int *msgvec;
+replyall(int *msgvec)
 {
        struct message *mp;
        char *cp, *rcv, *replyto;
@@ -239,6 +238,7 @@ _respond(msgvec)
                head.h_cc = np;
        } else
                head.h_cc = NULL;
+       head.h_inreplyto = hfield("message-id", mp);
        head.h_bcc = NULL;
        head.h_smopts = NULL;
        mail1(&head, 1);
@@ -586,9 +586,9 @@ Respond(void *v)
        int *msgvec = v;
 
        if (value("Replyall") == NULL)
-               return(_Respond(msgvec));
+               return(replyorig(msgvec));
        else
-               return(_respond(msgvec));
+               return(replyall(msgvec));
 }
 
 /*
@@ -597,7 +597,7 @@ Respond(void *v)
  * reply.
  */
 int
-_Respond(int *msgvec)
+replyorig(int *msgvec)
 {
        struct header head;
        struct message *mp;
@@ -619,6 +619,7 @@ _Respond(int *msgvec)
        if ((head.h_subject = hfield("subject", mp)) == NULL)
                head.h_subject = hfield("subj", mp);
        head.h_subject = reedit(head.h_subject);
+       head.h_inreplyto = hfield("message-id", mp);
        head.h_cc = NULL;
        head.h_bcc = NULL;
        head.h_smopts = NULL;
Index: src/usr.bin/mail//collect.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/collect.c,v
retrieving revision 1.33
diff -u -p -r1.33 collect.c
--- src/usr.bin/mail//collect.c 6 Apr 2011 11:36:26 -0000       1.33
+++ src/usr.bin/mail//collect.c 26 Jul 2011 13:15:26 -0000
@@ -328,7 +328,8 @@ cont:
                         */
                        rewind(collf);
                        puts("-------\nMessage contains:");
-                       puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL);
+                       puthead(hp, stdout,
+                           GTO|GSUBJECT|GCC|GBCC|GINREPLYTO|GNL);
                        while ((t = getc(collf)) != EOF)
                                (void)putchar(t);
                        goto cont;
Index: src/usr.bin/mail//def.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/def.h,v
retrieving revision 1.13
diff -u -p -r1.13 def.h
--- src/usr.bin/mail//def.h     25 Jun 2003 15:13:32 -0000      1.13
+++ src/usr.bin/mail//def.h     26 Jul 2011 13:15:26 -0000
@@ -155,11 +155,12 @@ struct headline {
        char    *l_date;        /* The entire date string */
 };
 
-#define        GTO     1               /* Grab To: line */
-#define        GSUBJECT 2              /* Likewise, Subject: line */
-#define        GCC     4               /* And the Cc: line */
-#define        GBCC    8               /* And also the Bcc: line */
-#define        GMASK   (GTO|GSUBJECT|GCC|GBCC)
+#define GTO            1       /* Grab To: line */
+#define GSUBJECT       2       /* Likewise, Subject: line */
+#define GCC            4       /* And the Cc: line */
+#define GBCC           8       /* And also the Bcc: line */
+#define GINREPLYTO     16      /* In-Reply-To: line */
+#define GMASK  (GTO|GSUBJECT|GCC|GBCC|GINREPLYTO)
                                /* Mask of places from whence */
 
 #define        GNL     16              /* Print blank line after */
@@ -173,6 +174,7 @@ struct headline {
 struct header {
        struct name *h_to;              /* Dynamic "To:" string */
        char *h_subject;                /* Subject string */
+       char *h_inreplyto;              /* In reply to */
        struct name *h_cc;              /* Carbon copies string */
        struct name *h_bcc;             /* Blind carbon copies */
        struct name *h_smopts;          /* Sendmail options */
Index: src/usr.bin/mail//extern.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/extern.h,v
retrieving revision 1.27
diff -u -p -r1.27 extern.h
--- src/usr.bin/mail//extern.h  28 Jul 2009 16:05:04 -0000      1.27
+++ src/usr.bin/mail//extern.h  26 Jul 2011 13:15:26 -0000
@@ -81,8 +81,6 @@ int    More(void *);
 int     Pclose(FILE *);
 int     Respond(void *);
 int     Type(void *);
-int     _Respond(int *);
-int     _respond(int *);
 void    alter(char *);
 int     alternates(void *);
 void    announce(void);
@@ -201,6 +199,8 @@ int  readline(FILE *, char *, int, int *
 void    register_file(FILE *, int, pid_t);
 void    regret(int);
 void    relsesigs(void);
+int     replyall(int *);
+int     replyorig(int *);
 int     respond(void *);
 int     retfield(void *);
 int     rexit(void *);
Index: src/usr.bin/mail//send.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/send.c,v
retrieving revision 1.22
diff -u -p -r1.22 send.c
--- src/usr.bin/mail//send.c    27 Oct 2009 23:59:40 -0000      1.22
+++ src/usr.bin/mail//send.c    26 Jul 2011 13:15:26 -0000
@@ -286,6 +286,7 @@ mail(struct name *to, struct name *cc, s
        head.h_subject = subject;
        head.h_cc = cc;
        head.h_bcc = bcc;
+       head.h_inreplyto = NULL;
        head.h_smopts = smopts;
        mail1(&head, 0);
        return(0);
@@ -306,6 +307,7 @@ sendmail(void *v)
        head.h_subject = NULL;
        head.h_cc = NULL;
        head.h_bcc = NULL;
+       head.h_inreplyto = NULL;
        head.h_smopts = NULL;
        mail1(&head, 0);
        return(0);
@@ -463,7 +465,7 @@ infix(struct header *hp, FILE *fi)
                return(fi);
        }
        (void)rm(tempname);
-       (void)puthead(hp, nfo, GTO|GSUBJECT|GCC|GBCC|GNL|GCOMMA);
+       (void)puthead(hp, nfo, GTO|GSUBJECT|GCC|GBCC|GINREPLYTO|GNL|GCOMMA);
        c = getc(fi);
        while (c != EOF) {
                (void)putc(c, nfo);
@@ -499,13 +501,15 @@ puthead(struct header *hp, FILE *fo, int
 
        gotcha = 0;
        if (hp->h_to != NULL && w & GTO)
-               fmt("To:", hp->h_to, fo, w&GCOMMA), gotcha++;
+               fmt("To:", hp->h_to, fo, w & GCOMMA), gotcha++;
        if (hp->h_subject != NULL && w & GSUBJECT)
                fprintf(fo, "Subject: %s\n", hp->h_subject), gotcha++;
        if (hp->h_cc != NULL && w & GCC)
-               fmt("Cc:", hp->h_cc, fo, w&GCOMMA), gotcha++;
+               fmt("Cc:", hp->h_cc, fo, w & GCOMMA), gotcha++;
        if (hp->h_bcc != NULL && w & GBCC)
-               fmt("Bcc:", hp->h_bcc, fo, w&GCOMMA), gotcha++;
+               fmt("Bcc:", hp->h_bcc, fo, w & GCOMMA), gotcha++;
+       if (hp->h_inreplyto != NULL && w & GINREPLYTO)
+               fprintf(fo, "In-Reply-To: %s\n", hp->h_inreplyto), gotcha++;
        if (gotcha && w & GNL)
                (void)putc('\n', fo);
        return(0);

Reply via email to