Package: bsd-mailx
Version: 8.1.2-0.20160123cvs-3.0teckids1
Severity: serious
Tags: patch
Justification: UTF-8 release goal

I’ve noticed that heirloom-mailx is gone and replaced with something
incompatible, leaving all systems with bsd-mailx. I’d normally use
bsd-mailx anyway, but on some systems we use heirloom-mailx because
it gets the charset right.

The attached patch fixes bsd-mailx to get the charset right: if the
user did not specify any headers, it adds MIME headers to indicate
the correct local charset (from the POSIX locale) and transfer
encoding.

I’m adding this as RC because I believe that the removal of
heirloom-mailx means that bsd-mailx ought to be fixed for stretch:
if this is not fixed, cron mails (e.g. from BSD calendar(1), but
also others) will have broken encoding.

-- System Information:
Debian Release: 9.0
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.9.0-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/lksh
Init: sysvinit (via /sbin/init)

Versions of packages bsd-mailx depends on:
ii  base-files                      9.9
ii  libbsd0                         0.8.3-1
ii  libc6                           2.24-9
ii  liblockfile1                    1.14-1+b1
ii  postfix [mail-transport-agent]  3.1.4-4

bsd-mailx recommends no packages.

bsd-mailx suggests no packages.

-- no debconf information
diff -Nru bsd-mailx-8.1.2-0.20160123cvs/debian/changelog 
bsd-mailx-8.1.2-0.20160123cvs/debian/changelog
--- bsd-mailx-8.1.2-0.20160123cvs/debian/changelog      2016-05-07 
09:34:12.000000000 +0200
+++ bsd-mailx-8.1.2-0.20160123cvs/debian/changelog      2017-04-09 
13:58:25.000000000 +0200
@@ -1,3 +1,10 @@
+bsd-mailx (8.1.2-0.20160123cvs-3.0teckids1) unstable; urgency=medium
+
+  * Non-maintainer upload.
+  * Add MIME headers if the user did not specify any additional headers.
+
+ -- Thorsten Glaser <t...@mirbsd.de>  Sun, 09 Apr 2017 13:58:25 +0200
+
 bsd-mailx (8.1.2-0.20160123cvs-3) unstable; urgency=medium
 
   * Make the `-b' option work again: update 03-Base-fixes-2.patch to revert
diff -Nru 
bsd-mailx-8.1.2-0.20160123cvs/debian/patches/33-add-mime-headers.patch 
bsd-mailx-8.1.2-0.20160123cvs/debian/patches/33-add-mime-headers.patch
--- bsd-mailx-8.1.2-0.20160123cvs/debian/patches/33-add-mime-headers.patch      
1970-01-01 01:00:00.000000000 +0100
+++ bsd-mailx-8.1.2-0.20160123cvs/debian/patches/33-add-mime-headers.patch      
2017-04-09 13:58:24.000000000 +0200
@@ -0,0 +1,71 @@
+Author: Thorsten Glaser <thorsten.gla...@teckids.org>
+Description: Add MIME headers if the user did not set any headers
+
+--- a/Makefile
++++ b/Makefile
+@@ -4,6 +4,7 @@ PROG=  mail
+ CC ?= gcc
+ 
+ CFLAGS += -D_DEFAULT_SOURCE -D_BSD_SOURCE -DDEBIAN -g -Wall
++CFLAGS += -D_GNU_SOURCE
+ 
+ SRCS= version.c aux.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c \
+       edit.c fio.c getname.c head.c v7.local.c lex.c list.c main.c names.c \
+--- a/main.c
++++ b/main.c
+@@ -34,6 +34,9 @@
+ #include <fcntl.h>
+ #include <sys/ioctl.h>
+ #include "extern.h"
++#include <errno.h>
++#include <locale.h>
++#include <langinfo.h>
+ 
+ static void   usage(void);
+       int     main(int, char **);
+@@ -58,6 +61,7 @@ main(int argc, char **argv)
+       char nosrc = 0;
+       char *rc;
+       extern const char version[];
++      char used_flag_a = 0;
+ 
+         /*
+        * drop any sgid/suid privileges
+@@ -70,6 +74,9 @@ main(int argc, char **argv)
+           err(1, "setuid");
+       }
+ 
++      /* Set the current user locale's charset. */
++      setlocale(LC_CTYPE, "");
++
+       /*
+        * Set up a reasonable environment.
+        * Figure out whether we are being run interactively,
+@@ -176,6 +183,7 @@ main(int argc, char **argv)
+                                       strcat(header, optarg);
+                               }
+                       }
++                      used_flag_a = 1;
+                       break;
+               case 'f':
+                       /*
+@@ -234,6 +242,19 @@ main(int argc, char **argv)
+                       /*NOTREACHED*/
+               }
+       }
++      if (!used_flag_a) {
++              /* Add locale-matching MIME headers. */
++              char *cp = NULL, *cs;
++
++              errno = 0;
++              cs = nl_langinfo(CODESET);
++              if (asprintf(&cp,
++                  "MIME-Version: 1.0\nContent-Type: text/plain; 
charset=\"%s\"\nContent-Transfer-Encoding: 8bit",
++                  cs && *cs ? cs : "ANSI_X3.4-1968") == -1 || !cp) {
++                      err(1, "out of memory");
++              }
++              header = cp;
++      }
+       if (ef != NULL) {
+               /* Check for optional mailbox file name. */
+               if (optind < argc) {
diff -Nru bsd-mailx-8.1.2-0.20160123cvs/debian/patches/series 
bsd-mailx-8.1.2-0.20160123cvs/debian/patches/series
--- bsd-mailx-8.1.2-0.20160123cvs/debian/patches/series 2016-05-07 
09:34:12.000000000 +0200
+++ bsd-mailx-8.1.2-0.20160123cvs/debian/patches/series 2017-04-09 
13:33:34.000000000 +0200
@@ -29,3 +29,4 @@
 30-Add-missing-includes.patch
 31-Do-not-call-pledge.patch
 32-Fix-FTBFS-on-Hurd.patch
+33-add-mime-headers.patch

Reply via email to