Download raw body.
mail(1) set Date and User-Agent [was: Re: Back to rfc2045]
In case anyone is afraid that my little original date() function could
be cut and pasted by someone to use it in some portable application
which, by chance, will be under some setlocale() instruction, here is a
boolet proof version using a what Sven suggested. (I had to include
locale.h in my other diffs anyways.)
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 3 Aug 2024 12:51:08 -0000
@@ -53,6 +53,7 @@
#include <termios.h>
#include <unistd.h>
#include <limits.h>
+#include <locale.h>
#include <vis.h>
#include "pathnames.h"
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 3 Aug 2024 12:51:08 -0000
@@ -100,6 +100,7 @@ int collabort(void);
void commands(void);
int copycmd(void *);
int count(struct name *);
+size_t date(char *str);
int deletecmd(void *);
int delm(int *);
int deltype(void *);
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 3 Aug 2024 12:51:08 -0000
@@ -516,15 +516,20 @@ puthead(struct header *hp, FILE *fo, int
{
int gotcha;
char *from;
+ char time[32];
gotcha = 0;
from = hp->h_from ? hp->h_from : value("from");
+ if (date(time) > 0 && fo != stdout)
+ fprintf(fo, "Date: %s\n", time), gotcha++;
if (from != NULL)
fprintf(fo, "From: %s\n", from), gotcha++;
if (hp->h_to != NULL && w & GTO)
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, "User-Agent: OpenBSD mail\n"), 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 3 Aug 2024 12:51:08 -0000
@@ -641,3 +641,28 @@ clearnew(void)
}
}
}
+
+size_t
+date(char *str)
+{
+ static locale_t cloc;
+ static char buf[32];
+ struct tm newtime;
+ time_t ltime;
+ size_t n;
+
+ if (cloc == (locale_t)0) {
+ cloc = newlocale(LC_ALL, "C", 0);
+ if (cloc == (locale_t) 0)
+ errx(1, "newlocale");
+ }
+
+ ltime = time(<ime);
+ localtime_r(<ime, &newtime);
+ n = strftime_l(buf, sizeof(buf), "%a, %d %b %Y %T %z", &newtime, cloc);
+
+ if (n > 0)
+ snprintf(str, sizeof(buf), "%s", buf);
+
+ return (n);
+}
--
Walter
mail(1) set Date and User-Agent [was: Re: Back to rfc2045]