Download raw body.
Adding Message-ID to mail(1) portable version ;-)
Index: def.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/def.h,v
diff -u -p -r1.17 def.h
--- def.h 28 Jan 2022 06:18:41 -0000 1.17
+++ def.h 20 Aug 2024 16:47:41 -0000
@@ -55,6 +55,9 @@
#include <limits.h>
#include <vis.h>
#include "pathnames.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
#define APPEND /* New mail goes to end of mailbox */
Index: extern.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/extern.h,v
diff -u -p -r1.30 extern.h
--- extern.h 21 May 2024 05:00:48 -0000 1.30
+++ extern.h 20 Aug 2024 16:47:41 -0000
@@ -129,6 +129,7 @@ int forward(char *, FILE *, char *, int
void free_child(pid_t);
int from(void *);
off_t fsize(FILE *);
+char* genmsgid(void);
int getfold(char *, int);
int gethfield(FILE *, char *, int, char **);
int gethfromtty(struct header *, int);
Index: send.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/send.c,v
diff -u -p -r1.26 send.c
--- send.c 8 Mar 2023 04:43:11 -0000 1.26
+++ send.c 20 Aug 2024 16:47:41 -0000
@@ -525,6 +525,8 @@ puthead(struct header *hp, FILE *fo, int
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 (fo != stdout)
+ fprintf(fo, "Message-ID: %s\n", genmsgid()), gotcha++;
if (hp->h_cc != NULL && w & GCC)
fmt("Cc:", hp->h_cc, fo, w&GCOMMA), gotcha++;
if (hp->h_bcc != NULL && w & GBCC)
Index: util.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/util.c,v
diff -u -p -r1.2 util.c
--- util.c 26 Dec 2022 19:16:01 -0000 1.2
+++ util.c 20 Aug 2024 16:47:41 -0000
@@ -641,3 +641,43 @@ clearnew(void)
}
}
}
+
+/* Generate Message-ID */
+char*
+genmsgid(void)
+{
+ struct addrinfo hints, *info, *p;
+ char *fqdn = NULL;
+ time_t t = time(NULL);
+ struct tm tm = *localtime(&t);
+ static char date[] = "YYYYmmdd.HHMMSS";
+ static char hostname[NI_MAXHOST];
+ static char buf[sizeof(date) + sizeof(hostname) + 4];
+ size_t size = 0;
+ int error = 0;
+
+ if (strftime(date, sizeof(date), "%Y%m%d.%H%M%S", &tm)
+ != sizeof(date) - 1)
+ errx(1, "genmsgid: strftime");
+
+ if (gethostname(hostname, sizeof(hostname)))
+ errx(1, "genmsgid: gethostname");
+
+ memset(&hints, 0, sizeof hints);
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_CANONNAME;
+
+ if (getaddrinfo(hostname, NULL, &hints, &info) != 0)
+ errx(1, "genmsgid: getaddrinfo");
+
+ for (p = info; p != NULL; p = p->ai_next)
+ fqdn = p->ai_canonname;
+
+ error = snprintf(buf, sizeof(buf), "<%s@%s>", date, fqdn);
+ if (error < 0 || error >= sizeof(buf))
+ errx(1, "genmsgid: snprintf");
+
+ freeaddrinfo(info);
+ return(buf);
+}
--
Walter
Adding Message-ID to mail(1) portable version ;-)