Package: apticron
Severity: normal
Tags: patch

Hi Tiago,

Please consider the attached patch. This time, the patch has actually
been tested.

Regards,
 Nis
>From 5f800612e607bc854b5a0a5399a3911ec2b85701 Mon Sep 17 00:00:00 2001
From: Nis Martensen <[email protected]>
Date: Sun, 24 May 2009 11:08:41 +0200
Subject: [PATCH] Make apticron work correctly with more mailx implementations

BSD-mailx and mailutils' mailx don't do character set detection or
conversion, but do not send proper mime-headers either. Therefore, make
them send correct headers by means of their -a option.

Heirloom-mailx detects the message charset, can do character set
conversion and sends proper mime-headers. However, correct character set
detection depends on the LC_CTYPE locale setting. The Debian changelog
entries (which apticron is sending) are encoded in UTF-8. Detection can
fail if LC_CTYPE is not set to a UTF-8 locale, in which case the message
might be sent as application/octet-stream. Setting ttycharset to utf-8
makes it use a text/plain content type.
---
 apticron |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/apticron b/apticron
index 1b3d3cb..fcc9211 100755
--- a/apticron
+++ b/apticron
@@ -13,6 +13,25 @@ isDigit() {
 
 }
 
+# Character set handling differs between the different mailx
+# implementations in Debian. Make sure we send proper headers, and a
+# text/plain content type.
+Mailx() {
+       if [ "x`readlink -e /usr/bin/mailx`" = "x/usr/bin/heirloom-mailx" ]
+       then
+               # heirloom-mailx creates correct headers, but needs help
+               # if the terminal charset (LC_CTYPE) is no UTF-8 locale
+               /usr/bin/mailx -S ttycharset=utf-8 "$@"
+       else
+               # bsd-mailx/mailutils' mailx don't do character set
+               # conversion, but do not support MIME either.
+               /usr/bin/mailx -a "MIME-Version: 1.0" \
+                       -a "Content-type: text/plain; charset=UTF-8" \
+                       -a "Content-transfer-encoding: 8bit" \
+                       "$@"
+       fi
+}
+
 if [ "x$1" = "x--cron" ] ; then
 
        shift
@@ -237,7 +256,7 @@ EOF
 apticron
 EOF
 
-   ) 2>&1 | /usr/bin/mailx -a "Content-type: text/plain; charset=UTF-8" -s 
"$DISTRIB_ID package updates on $SYSTEM" $EMAIL
+   ) 2>&1 | Mailx -s "$DISTRIB_ID package updates on $SYSTEM" $EMAIL
 
 fi
 
-- 
1.5.6.5

Reply via email to