• Walter Alejandro Iglesias [2023-09-20 12:21]:
Hi Ingo,

I did what you suggested me, I investigated a bit and you were right in
that the MIME-Version header was necessary.  This new set of patches
add the following headers (hardcoded as you suggested me):

   MIME-Version: 1.0
   Content-Type: text/plain; charset=utf-8
   Content-Transfer-Encoding: 8bit

I modified the code the less as possible, just a '-m' option:

   $ mail -m -s Hello d...@ext.net < body_message_in_utf8

you may not even need -m, and instead inspect LC_CTYPE environment variable and add appropriate headers for UTF-8. according to locale(1), LC_CTYPE may be set to indicate UTF-8:

If the value of LC_CTYPE ends in ‘.UTF-8’, programs in the OpenBSD base system ignore the beginning of it, treating for example zh_CN.UTF-8 exactly like en_US.UTF-8.

Although, to tell the truth, I'm not really convinced if this change is
worth it.  Feel free to ignore it.



Index: extern.h
===================================================================
RCS file: /cvs/src/usr.bin/mail/extern.h,v
retrieving revision 1.29
diff -u -p -r1.29 extern.h
--- extern.h    16 Sep 2018 02:38:57 -0000      1.29
+++ extern.h    20 Sep 2023 09:55:06 -0000
@@ -261,3 +261,4 @@ int  writeback(FILE *);
  extern char *__progname;
  extern char *tmpdir;
  extern const struct cmd *com; /* command we are running */
+extern char mime; /* Add MIME headers */
Index: mail.1
===================================================================
RCS file: /cvs/src/usr.bin/mail/mail.1,v
retrieving revision 1.83
diff -u -p -r1.83 mail.1
--- mail.1      31 Mar 2022 17:27:25 -0000      1.83
+++ mail.1      20 Sep 2023 09:55:06 -0000
@@ -106,6 +106,8 @@ on noisy phone lines.
  .It Fl N
  Inhibits initial display of message headers
  when reading mail or editing a mail folder.
+.It Fl m
+Add MIME headers to send utf-8 encoded messages.
  .It Fl n
  Inhibits reading
  .Pa /etc/mail.rc
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mail/main.c,v
retrieving revision 1.35
diff -u -p -r1.35 main.c
--- main.c      26 Jan 2021 18:21:47 -0000      1.35
+++ main.c      20 Sep 2023 09:55:06 -0000
@@ -79,6 +79,8 @@ int   realscreenheight;               /* the real scree
  int   uflag;                          /* Are we in -u mode? */
  sigset_t intset;                      /* Signal set that is just SIGINT */
+char mime = 0; /* Add MIME headers */
+
  /*
   * The pointers for the string allocation routines,
   * there are NSPACE independent areas.
@@ -136,7 +138,7 @@ main(int argc, char **argv)
        smopts = NULL;
        fromaddr = NULL;
        subject = NULL;
-       while ((i = getopt(argc, argv, "EINb:c:dfinr:s:u:v")) != -1) {
+       while ((i = getopt(argc, argv, "EINb:c:dfimnr:s:u:v")) != -1) {
                switch (i) {
                case 'u':
                        /*
@@ -171,6 +173,10 @@ main(int argc, char **argv)
                         */
                        subject = optarg;
                        break;
+               case 'm':
+                       /* Add MIME headers */
+                       mime = 1;
+                       break;
                case 'f':
                        /*
                         * User is specifying file to "edit" with Mail,
@@ -337,7 +343,7 @@ __dead void
  usage(void)
  {
- fprintf(stderr, "usage: %s [-dEIinv] [-b list] [-c list] "
+       fprintf(stderr, "usage: %s [-dEIimnv] [-b list] [-c list] "
            "[-r from-addr] [-s subject] to-addr ...\n", __progname);
        fprintf(stderr, "       %s [-dEIiNnv] -f [file]\n", __progname);
        fprintf(stderr, "       %s [-dEIiNnv] [-u user]\n", __progname);
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 09:55:06 -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 (mime)
+               fprintf(fo, "MIME-Version: 1.0\nContent-Type: text/plain; 
charset=utf-8\nContent-Transfer-Encoding: 8bit\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)




Reply via email to