altermime is a postfix filter that allows you to alter MIME encoded content in outgoing and incoming messages. we wanted to append a disclaimer to the bottom of all outgoing emails from our server automatically, without having to rely on each individual manually adding this to their outlook signature or using a template.
the problem was that altermime (0.3.8) was appending “soft breaks” or “= ” (equal sign and a space) after every 76 characters inside the disclaimer in every multipart email that outlook would send out.
the source file qpe.c from the package here was the culprit, and though it was doing it’s job correctly, it wasn’t doing it how we needed it to be done.
i have modified the code and created a diff patch, located here. i take no responsibility for you screwing something up by using this patch incorrectly. i tested it and it works… and it makes altermime do what we needed it to do for outlook compatible automatic disclaimer insertion.
to patch your source file simply change to the directory where qpe.c is located and issue the following command:
<code>
patch -p0 < patch.qpe.c
</code>
and then, assuming your install directory is configured correctly in the Makefile,
<code>
make clean; make; make install
</code>
also, below is the modified the disclaimer shell script that will:
- only include the disclaimer once in each email “thread”
- only append the disclaimer when parties whom have emails outside of your domain are part of the email
here is the code:
<code>
#!/bin/bash -u
# Localize these.
MYDOMAIN=r0b0tz.com
# make sure that the text "$MYDOMAIN disclaimer" (ie: "r0b0tz.com disclaimer") is in
# all of your disclaimer text / html files, otherwise the single include only will not work.
INSPECT_DIR=/var/spool/filter
SENDMAIL=/usr/sbin/sendmail
# Exit codes from
EX_TEMPFAIL=75
EX_UNAVAILABLE=69
# Clean up when done or when aborting.
trap "rm -f in.$$" 0 1 2 3 15
# Start processing.
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit
$EX_TEMPFAIL; }
cat >in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }
nmecount=0
if [ ! `grep -m 1 '${MYDOMAIN} disclaimer' in.$$` ]; then
for b in $( grep -m 1 "To:" in.$$ | grep -io '<[a-zA-Z0-9.-]*\@[a-zA-Z0-9.-]*\.[a-zA-Z]*>' in.$$ )
do
i=`echo ${b} | cut -d "," -f 1`
if [[ "${i}" =~ '(.*)@(.*)\.(.*)' ]]; then
logger -t DISCLAIMER outgoing email: ${i}
if [[ ! "${i}" =~ '(.*)@${MYDOMAIN}' ]] && [[ ! "${i}" =~ '(.*)@mail\.${MYDOMAIN}' ]]; then
nmecount=1
fi
fi
done
fi
if [ "${nmecount}" == 1 ]; then
# Adding disclaimer
# MAKE SURE YOU MODIFY THE LOCATIONS OF YOUR DISCLAIMERS!
/usr/bin/altermime --multipart-insert --input=in.$$ \
--disclaimer=/etc/postfix/disclaimer.txt \
--disclaimer-html=/etc/postfix/disclaimer.html \
--disclaimer-b64=/etc/postfix/disclaimer.b64 \
--xheader="X-Copyrighted-Material: Please visit http://${MYDOMAIN}/" || \
{ echo Message content rejected; exit $EX_UNAVAILABLE; }
fi
####### Changed From Original Script END #######
$SENDMAIL "$@"
</code>
… or click here to download.