Hi Ingo, On Thu, Sep 21, 2023 at 03:04:24PM +0200, Ingo Schwarze wrote: > As Stefan says, adding a hand-written UTF-8 parser to mail(1) is > clearly not acceptable.
Below, a version without utf8 parser. I added a ASCII check for the subject. The day will come when wscons support UTF-8, right? In the meantime, just by being careful not to type iso-latin characters while using mail on wscons this version does its job. > > Yours, > Ingo Index: send.c =================================================================== RCS file: /cvs/src/usr.bin/mail/send.c,v retrieving revision 1.26 diff -u -p -r1.26 send.c --- send.c 8 Mar 2023 04:43:11 -0000 1.26 +++ send.c 22 Sep 2023 03:54:37 -0000 @@ -33,6 +33,10 @@ #include "rcv.h" #include "extern.h" +/* This will be used to add MIME headers */ +static char noascii_subject; +static char noascii_body; + static volatile sig_atomic_t sendsignal; /* Interrupted by a signal? */ /* @@ -341,6 +345,22 @@ mail1(struct header *hp, int printheader else puts("Null message body; hope that's ok"); } + + /* Check for non ascii characters in the subject */ + int i, ch; + i = 0; + while (hp->h_subject[i] != '\0') { + if (!isascii(hp->h_subject[i])) + noascii_subject = 1; + i++; + } + + /* Check for non ascii characters in the body */ + while ((ch = getc(mtf)) != EOF) + if (!isascii(ch)) + noascii_body = 1; + rewind(mtf); + /* * Now, take the user names from the combined * to and cc lists and do all the alias @@ -524,7 +544,18 @@ puthead(struct header *hp, FILE *fo, int 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++; + fprintf(fo, "Subject: %s\n", hp->h_subject), + gotcha++; + if (noascii_subject || noascii_body) + fprintf(fo, "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=utf-8\n" + "Content-Transfer-Encoding: 8bit\n"), + gotcha++; + else + fprintf(fo, "MIME-Version: 1.0\n" + "Content-Type: text/plain; charset=us-ascii\n" + "Content-Transfer-Encoding: 7bit\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) @@ -607,6 +638,5 @@ savemail(char *name, FILE *fi) void sendint(int s) { - sendsignal = s; } -- Walter