Download raw body.
mail(1) set Date and User-Agent [was: Re: Back to rfc2045]
On 2024/08/01 20:33:17 +0200, Omar Polo <op@omarpolo.com> wrote:
> On 2024/08/01 20:00:57 +0200, Omar Polo <op@omarpolo.com> wrote:
> > On 2024/08/01 10:41:40 +0200, Walter Alejandro Iglesias <wai@roquesor.com> wrote:
> > > I fixed some mistakes and simplified a bit the code:
> > >
> > > https://en.roquesor.com/Downloads/mail_patches.tar.gz
> > >
> > > I understand why my proposal doesn't attract too much attention, I can
> > > count only one person here using mail(1) as a MUA. Anyway, I'd like to
> > > know if I'm doing something wrong.
> > >
> > > At least I'd appreciate some guidance about the general procedure.
> > > Regarding the size, for example, I understand conceptually the
> > > convenience of splitting and committing a diff in small chunks to gain
> > > control and avoid introducing regressions, but isn't it necessary to
> > > test the full functional patches first, to evaluate what they do?
> >
> > No, it is not. For example, Date and User-agent are completely
> > orthogonal to MIME support or UTF8. So, while I'm happy to see this
> > interest in improving mail(1), let's try to get it down to small pieces
> > that can be reviewed and everyone agree on. Especially when some
> > "controversial" or, rather, delicate topics like UTF-8 are involved.
> > The risk is to derail the thread on some details and so loosing all the
> > other stuff.
> >
> > So, let's discuss the first (?) patch, the one to add the Date and
> > User-Agent header. We'll do separate threads for the others when I'll
> > get to review them.
> >
> > Personally I don't feel a strong need for User-Agent, but given that
> > even mblaze(1) sets it by default I think it's fine. I'm a bit unsure
> > about the format, your diff has "OpenBSD mail(1)" and the (...) are
> > usually comments in mail headers, so I've changed it to just "OpenBSD
> > mail".
> >
> > Then, we can't use strftime() since it depends on the locale. (On
> > OpenBSD this technically doesn't matter, but let's do the right thing.)
> > So, I've stolen a function from OpenSMTPD. (which opens the problem of
> > the copyright and ISC vs BSD 3 clausole)
> >
> > Anyway, here's the diff. Except for the copyright "problem" from which
> > I'd like to hear other opinions, I think this is fine and is ok op@ if
> > someone wants to go ahead with this.
>
> Here's the same diff but with the date() function in a separate file to
> be precise and correct about the copyright; thanks deraadt for the idea.
now with the proper function in the errx() case. thank tb for spotting
the typo.
third's the chance.
diff /home/op/w/mail
commit - 80617155f9fa32a62f9dbcbea7b90ebbdb39ec14
path + /home/op/w/mail
blob - e2313ca24a3967e3558fcb2193dbed89c35b3b19
file + Makefile
--- Makefile
+++ Makefile
@@ -1,7 +1,7 @@
# $OpenBSD: Makefile,v 1.13 2020/12/15 00:50:01 daniel Exp $
PROG= mail
-SRCS= version.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c \
+SRCS= version.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c date.c \
edit.c fio.c head.c v7.local.c lex.c list.c main.c names.c \
popen.c quit.c send.c strings.c temp.c tty.c util.c vars.c
SFILES= mail.help mail.tildehelp
blob - /dev/null
file + date.c (mode 644)
--- /dev/null
+++ date.c
@@ -0,0 +1,67 @@
+/* $OpenBSD$ */
+
+/*
+ * Copyright (c) 2009 Jacek Masiulaniec <jacekm@dobremiasto.net>
+ * Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
+ * Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/time.h>
+
+#include <err.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "def.h"
+#include "extern.h"
+
+char *
+date(void)
+{
+ struct tm *lt;
+ static char buf[40];
+ const char *day[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+ const char *month[] = {"Jan","Feb","Mar","Apr","May","Jun",
+ "Jul","Aug","Sep","Oct","Nov","Dec"};
+ const char *tz;
+ time_t now;
+ long offset;
+ int r;
+
+ now = time(NULL);
+ lt = localtime(&now);
+ if (lt == NULL || now == 0)
+ err(1, "date: localtime");
+
+ offset = lt->tm_gmtoff;
+ tz = lt->tm_zone;
+
+ /* We do not use strftime because it is subject to locale substitution*/
+ r = snprintf(buf, sizeof(buf),
+ "%s, %d %s %d %02d:%02d:%02d %c%02d%02d (%s)",
+ day[lt->tm_wday], lt->tm_mday, month[lt->tm_mon],
+ lt->tm_year + 1900,
+ lt->tm_hour, lt->tm_min, lt->tm_sec,
+ offset >= 0 ? '+' : '-',
+ abs((int)offset / 3600),
+ abs((int)offset % 3600) / 60,
+ tz);
+ if (r < 0 || (size_t)r >= sizeof(buf))
+ errx(1, "date: snprintf");
+
+ return buf;
+}
blob - 95508398058ef09067b62f596685a602cabbe85e
file + extern.h
--- extern.h
+++ extern.h
@@ -100,6 +100,7 @@ int collabort(void);
void commands(void);
int copycmd(void *);
int count(struct name *);
+char *date(void);
int deletecmd(void *);
int delm(int *);
int deltype(void *);
blob - 9582675f9b851583f8487aae8ff1b82e70bf01d4
file + send.c
--- send.c
+++ send.c
@@ -519,12 +519,16 @@ puthead(struct header *hp, FILE *fo, int w)
gotcha = 0;
from = hp->h_from ? hp->h_from : value("from");
+ if (date() != NULL && fo != stdout)
+ fprintf(fo, "Date: %s\n", date()), 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)
mail(1) set Date and User-Agent [was: Re: Back to rfc2045]