Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 201628 - sys-power/apcupsd event scripts don't use sendmail (ssmtp) properly, subject treated as recipient, body is ignored
Summary: sys-power/apcupsd event scripts don't use sendmail (ssmtp) properly, subject ...
Status: RESOLVED DUPLICATE of bug 254242
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: High normal (vote)
Assignee: Michael Imhof (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-07 23:43 UTC by Michael Yagliyan
Modified: 2009-01-15 15:20 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Yagliyan 2007-12-07 23:43:01 UTC
The various event scripts in /etc/apcupsd (onbattery, commfailure, etc.) all do the following to formulate a message (edited for simplicity):

MSG="$HOSTNAME UPS battery needs changing NOW."
#
(
   echo "Subject: $MSG"
   echo "To: $SYSADMIN"
   echo " "
   echo "$MSG"
   echo " "
   /sbin/apcaccess status
) | sendmail -s "$MSG" $SYSADMIN

On my system anyway, the virtual/mta requirement was satisfied by ssmtp.  At least with ssmtp's implementation of sendmail, the following things are wrong with the script excerpt above:
- The echo after To: puts a space on the next line instead of a blank line.  For whatever reason, this causes ssmtp to not treat the rest of the message as the body, even though it does read it (as is evident when using the -v option with sendmail).
- The -s option passed to sendmail is not supported in ssmtp it seems.  As such, that text is treated as a recipient address.

I am not familiar with other sendmail implementations, but at least for me, here is what I did to fix these issues:
- Change echo " " to echo ""
- Change sendmail arguments from -s "$MSG" $SYSADMIN to -t (-t because it is also unnecessary to specify To in both the message and the command line, -t tells sendmail to use the To address in the message)

Below is my /etc/ssmtp/ssmtp.conf:
root=myusername@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
hostname=myusername@gmail.com
FromLineOverride=YES
UseSTARTTLS=YES
AuthUser=myusername@gmail.com
AuthPass=mypassword

Below is my /etc/ssmtp/revaliases:
root:myusername@gmail.com:smtp.gmail.com:587
mainuser:myusername@gmail.com:smtp.gmail.com:587

Reproducible: Always

Steps to Reproduce:
1. Install and configure apcupsd and ssmtp.  apcupsd does not need to be set explicitly to email on an event, the scripts already do it provided sendmail (or equivalent) is setup.
2. Cause one of the events to occur or just manually run one of event scripts.
3. Check your e-mail.

Actual Results:  
The account being used to send the mail received a Delivery Status Notification (or whatever it is called) message that the recipient address was not found.  This message showed that some or all of the subject line was treated as an address.

The account the notification was sent to received the e-mail, but with an empty body.

Expected Results:  
The message was supposed to be sent to the recipient address, with the body intact.

Portage 2.1.3.19 (default-linux/amd64/2006.1/desktop, gcc-4.1.2, glibc-2.6.1-r0, 2.6.23-gentoo-r3 x86_64)
=================================================================
System uname: 2.6.23-gentoo-r3 x86_64 AMD Athlon(tm) 64 Processor 3700+
Timestamp of tree: Mon, 03 Dec 2007 04:00:01 +0000
app-shells/bash:     3.2_p17
dev-java/java-config: 1.3.7, 2.0.33-r1
dev-lang/python:     2.4.4-r6
dev-python/pycrypto: 2.0.1-r6
sys-apps/baselayout: 1.12.9-r2
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.3.16
sys-devel/libtool:   1.5.24
virtual/os-headers:  2.6.22-r2
ACCEPT_KEYWORDS="amd64"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=athlon64 -msse3 -pipe -O2"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/gconf /etc/revdep-rebuild /etc/splash /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-march=athlon64 -msse3 -pipe -O2"
DISTDIR="/usr/portage/distfiles"
FEATURES="distlocks metadata-transfer sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="ftp://mirror.iawnet.sandia.gov/pub/gentoo/ ftp://ftp.ussg.iu.edu/pub/linux/gentoo http://gentoo.mirrors.pair.com/ ftp://gentoo.mirrors.pair.com/ http://gentoo.netnitco.net ftp://gentoo.netnitco.net/pub/mirrors/gentoo/source/ http://gentoo.binarycompass.org "
LANG="en_US"
LINGUAS="en"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X a52 aac acpi alsa amd64 arts audiofile bash-completion berkdb bitmap-fonts cairo cdr cli cracklib crypt cups dbus dri dts dvd dvdr dvdread eds emboss encode fam ffmpeg firefox flac fortran gdbm gif gpm hal iconv idn imlib ipv6 isdnlog jbig jpeg jpeg2k kde ladspa libsamplerate logitech-mouse mad matroska midi mikmod mng mp3 mpeg mudflap ncurses nls nptl nptlonly ogg opengl openmp pam pcre pdf perl png ppds pppd python qt3 qt4 quicktime readline reflection rle sdl session spell spl ssl svg tcpd theora threads tiff truetype truetype-fonts type1-fonts unicode usb vcd vorbis wmf x264 xcomposite xine xml xorg xv xvid xvmc zlib" ALSA_CARDS="intel8x0" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en" USERLAND="GNU" VIDEO_CARDS="nv nvidia vesa"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LDFLAGS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, PORTDIR_OVERLAY
Comment 1 Alin Năstac (RETIRED) gentoo-dev 2008-01-04 09:14:23 UTC
echo " " lines should be replaced by a simple echo.
Comment 2 Alin Năstac (RETIRED) gentoo-dev 2008-01-20 09:42:58 UTC
Why did you marked 3.12.4 as stable? You have many open bugs that need to be addressed, including this one!
Comment 3 Michael Yagliyan 2008-01-20 10:54:51 UTC
> - The -s option passed to sendmail is not supported in ssmtp it seems.  As
> such, that text is treated as a recipient address.

I am not familiar with how a sendmail command should be implemented or how the interface is specified, but it occurs to me now that this problem with the -s option in ssmtp is actually a bug with ssmtp.  I mean if the -s option is not supported by ssmtp, it should correctly ignore that option and any of that option's possible arguments, right?  If so, then the only thing that really MUST be corrected is the echo thing.
Comment 4 Stefano Torresi 2008-06-17 02:58:03 UTC
i'm facing the same problem using netqmail as mta. the sendmail wrapper doesn't have the -s option, so i had to change all the event scripts to make them use /bin/mail instead of /usr/sbin/sendmail.
i guess it would be nice at least a post-inst notification or, even better, some way to customize the APCUPSD_MAIL variable, which is currently hard-coded in the ebuild, prior to installation.
Comment 5 Diego Elio Pettenò (RETIRED) gentoo-dev 2009-01-15 15:20:31 UTC

*** This bug has been marked as a duplicate of bug 254242 ***