On Wed, Sep 20, 2023 at 06:13:10PM +0200, Walter Alejandro Iglesias wrote:
> Now I was investigating exactly that :-) (like Mutt also does): to make
> mail(1) automatically set the appropiate MIME headers when it detects
> any utf8 characters in the body text. So, you don't like this idea?
>
And this new idea simplifies all to this:
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 20 Sep 2023 17:40:22 -0000
@@ -33,6 +33,8 @@
#include "rcv.h"
#include "extern.h"
+char utf8 = 0;
+
static volatile sig_atomic_t sendsignal; /* Interrupted by a signal? */
/*
@@ -341,6 +343,13 @@ mail1(struct header *hp, int printheader
else
puts("Null message body; hope that's ok");
}
+ /* Check for non ascii characters */
+ int ch;
+ while ((ch = getc(mtf)) != EOF)
+ if (ch > 0x7f)
+ utf8 = 1;
+ rewind(mtf);
+
/*
* Now, take the user names from the combined
* to and cc lists and do all the alias
@@ -525,6 +534,10 @@ 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 (utf8)
+ fprintf(fo, "MIME-Version: 1.0\nContent-Type: text/plain;
charset=utf-8\nContent-Transfer-Encoding: 8bit\n"), gotcha++;
+ else
+ fprintf(fo, "MIME-Version: 1.0\nContent-Type: text/plain;
charset=us-ascii\nContent-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)
--
Walter