Download raw body.
Adding Message-ID to mail(1) portable version ;-)
On Wed, Aug 21, 2024 at 07:52:33AM +0200, Walter Alejandro Iglesias wrote:
> By the way, I'd already had the POSIX compliant non-portable version
> (pasted below.) I posted the other one because of what I was told about
> "portability". When you guys agree on what should be done (at least in
> this case) I would appreciate it if you let me know.
>
My POSIX version had one variable left unused.
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 21 Aug 2024 11:35:49 -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 21 Aug 2024 11:35:49 -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 21 Aug 2024 11:35:49 -0000
@@ -641,3 +641,28 @@ clearnew(void)
}
}
}
+
+/* Generate Message-ID */
+char*
+genmsgid(void)
+{
+ time_t t = time(NULL);
+ struct tm tm = *localtime(&t);
+ static char date[] = "YYYYmmdd.HHMMSS";
+ static char hostname[HOST_NAME_MAX+1];
+ static char buf[sizeof(date) + sizeof(hostname) + 4];
+ int error = 0;
+
+ if (gethostname(hostname, sizeof(hostname)))
+ errx(1, "genmsgid: gethostname");
+
+ if (strftime(date, sizeof(date), "%Y%m%d.%H%M%S", &tm)
+ != sizeof(date) - 1)
+ errx(1, "genmsgid: strftime");
+
+ error = snprintf(buf, sizeof(buf), "<%s@%s>", date, hostname);
+ if (error >= sizeof(buf) || error < 0)
+ errx(1, "genmsgid: snprintf");
+
+ return(buf);
+}
--
Walter
Adding Message-ID to mail(1) portable version ;-)