Adding a disclaimer (altermime) or footer

From Zimbra :: Wiki

Jump to: navigation, search

Note: This article adds footer text to all mails sent by Zimbra users. See also the very cool http://wiki.zimbra.com/index.php?title=Domain_Disclaimer_Extension_Admin_UI

Altermime


  • 2) Compile
  make

(note: on some 64-bit systems, like CentOS 64-bit, there are problems compiling the source. For me the quick&dirty solution is to edit the Makefile end erase the "-Werror" option.)

  • 3) Install altermime
  cp altermime /usr/bin/
  chown root.root /usr/bin/altermime
  chmod 755 /usr/bin/altermime


  • 4) Add a "filter" user
  useradd -r -c "Postfix Filters" -d /var/spool/filter filter


  • 5) Create a filter directory
  mkdir /var/spool/filter
  chown filter.filter /var/spool/filter
  chmod 750 /var/spool/filter

Postfix

  • 6) Backup you master.cf file
  cp /opt/zimbra/postfix/conf/master.cf /opt/zimbra/postfix/conf/master.cf.orig
  • 6.A) For zimbra >6 Backup your master.cf.in file
  cp /opt/zimbra/postfix/conf/master.cf.in /opt/zimbra/postfix/conf/master.cf.in.orig
  • 7) Modify /opt/zimbra/postfix/conf/master.cf (/opt/zimbra/postfix/conf/master.cf.in for version > 5.0.10)
  smtp      inet  n       -       n       -       -       smtpd
      -o content_filter=dfilt:
  dfilt   unix    -       n       n       -       -       pipe
      flags=Rq user=filter argv=/opt/zimbra/postfix/conf/disclaimer -f ${sender} -- ${recipient}
  


  • 7a) OPTION. To ensure disclaimer is added only to outbound mail:
   192.168.0.1:smtp    inet  n       -       n       -       -       smtpd
   192.168.0.2:smtp    inet  n       -       n       -       -       smtpd
      -o content_filter=dfilt:
   127.0.0.1:smtp      inet  n       -       n       -       -       smtpd
      -o content_filter=dfilt:
   dfilt   unix    -       n       n       -       -       pipe
   flags=Rq user=filter argv=/opt/zimbra/postfix/conf/disclaimer -f ${sender} -- ${recipient}
  • 7b) OPTION. To ensure disclaimer is added only to outbound mail with some other options, there is another solution, maybe simplier - here use the same code from the point 7), but use another, alternative, script "disclaimer" in point 9a).
  • 7c) OPTION. you may also add the filter to alternate ports, such as submission(587)
   submission inet n      -       n       -       -       smtpd
      -o content_filter=dfilt:


  • 8) Create a disclaimer file in /opt/zimbra/postfix/conf/disclaimer.txt and disclaimer.html

For example:
/opt/zimbra/postfix/conf/disclaimer.txt

  _____________________________________________________________________
  
  This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed.
  If you have received this email in error please notify the system manager. Please note that any views or opinions presented in this email are solely   
  those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for 
  the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
  
  Company X, Suite# 1, Street, City, Country, www.company.com


/opt/zimbra/postfix/conf/disclaimer.html

   _____________________________________________________________________<br>
   <br>
   This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed.<br>
   If you have received this email in error please notify the system manager. Please note that any views or opinions presented in this email are solely   <br>
   those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for <br>
   the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.<br>
   <br>
   Company X, Suite# 1, Street, City, Country, <a href="http://www.company.com"><b>www.company.com<b></a><br>


  • 9) Create disclaimer script in /opt/zimbra/postfix/conf/disclaimer
  #!/bin/sh
  INSPECT_DIR=/var/spool/filter
  SENDMAIL=/opt/zimbra/postfix/sbin/sendmail
  FOLDER_DISCLAIMER=/opt/zimbra/postfix/conf
  
  # Exit codes from <sysexits.h>
  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; }
  
  TEXT_DISCLAIMER=`grep "[a|A-z|Z]" ${FOLDER_DISCLAIMER}/disclaimer.txt | grep -v "_" | tail -2 | head -1`
  
  cat > in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }
  
  nohup grep "${TEXT_DISCLAIMER}" in.$$ > /dev/null 2>&1
  
  if [ ! "$?" = 0 ]; then
  /usr/bin/altermime --input=in.$$ --disclaimer=${FOLDER_DISCLAIMER}/disclaimer.txt --disclaimer-html=${FOLDER_DISCLAIMER}/disclaimer.html \
  --xheader="X-Copyrighted-Material: Please visit www.company.com/privacy.htm" || { echo Message content rejected; exit $EX_UNAVAILABLE; }
  fi
  
  $SENDMAIL -i "$@" < in.$$
  
  exit $?
  • 9a) OPTION: To ensure that the disclaimer is added only if:
    • the mail body doesn't contents the disclaimer in this moment (i.e. because of Reply to the mail containing disclaimer; please note the presence of disclaimer is verified by the presence of the fourth line from the end of disclaimer.txt in the body of the mail);
    • the sender is from the domain defined in the DOMAIN variable (so, there are only outgoing mail affected) - remember to edit line 5 of the script!;
    • the recipient is NOT from the domain defined in the DOMAIN variable (so, the mails destinated to the same domain doesn't need the disclaimer).


Create disclaimer script in /opt/zimbra/postfix/conf/disclaimer containing

   #!/bin/sh
   INSPECT_DIR=/var/spool/filter
   SENDMAIL=/opt/zimbra/postfix/sbin/sendmail
   FOLDER_DISCLAIMER=/opt/zimbra/postfix/conf
   DOMAIN="example.com"
   
   # Exit codes from <sysexits.h>
   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; }
   
   TEXT_DISCLAIMER=`grep "[[:alnum:]]" ${FOLDER_DISCLAIMER}/disclaimer.txt | grep -v "_" | tail -4 | head -1`
   cat > in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; }
   
   # Verify if is there the disclaimer present in the mail body
   grep -q "${TEXT_DISCLAIMER}" in.$$
   let R1="$?"
   
   # Verify if the sender is from DOMAIN
   #grep "From:" in.$$ | head -1 | grep -i $DOMAIN > /dev/null 2>&1
   echo "$2" | grep -i -q "$DOMAIN"
   let R2="$?"
   
   # Verify if the recipient is from DOMAIN
   echo "$4" | grep -i -q "$DOMAIN"
   let R3="$?"
   
   if [[ $R1 != 0 && $R2 == 0 && $R3 != 0 ]]; then
       /usr/bin/altermime --input=in.$$ \
                      --disclaimer=${FOLDER_DISCLAIMER}/disclaimer.txt \
                      --disclaimer-html=${FOLDER_DISCLAIMER}/disclaimer.html || \
                      { echo -e \n Message content rejected; exit $EX_UNAVAILABLE; }
   fi
   
   $SENDMAIL -i "$@" < in.$$
   
   exit $?
  • 10) Set permissions
  chgrp filter /opt/zimbra/postfix/conf/disclaimer*
  chmod 750 /opt/zimbra/postfix/conf/disclaimer

Just change the group of all the disclaimer files (disclaimer, disclaimer.txt and disclaimer.html)
to let the filter user to have access to them - Octavio Luna

  • 11) Restart Zimbra postfix
  su - zimbra
  zmmtactl stop
  zmmtactl start


Good luck!
--
Daniel Eugenin M.
IT Linux Ltda.


Update: Adding a diferent disclaimer by domain

Only you must change:

  • 8) Create an disclaimer file per domain and an empty file:

For example:

mkdir /opt/zimbra/postfix/conf/disclaimers
/opt/zimbra/postfix/conf/disclaimers/domain1.txt
/opt/zimbra/postfix/conf/disclaimers/domain2.txt
/opt/zimbra/postfix/conf/disclaimers/emptydisclaimer.txt
  • 9) Create disclaimer script in /opt/zimbra/postfix/conf/disclaimer
#!/bin/sh
INSPECT_DIR=/var/spool/filter
SENDMAIL=/opt/zimbra/postfix/sbin/sendmail
LOCAL_DOMAIN1=domain1.com
LOCAL_DOMAIN2=domain2.com
RECIP=`echo $* | awk '{print $NF}'| tr [A-Z] [a-z]`
RECIP_DOMAIN=`echo $RECIP | awk -F"@" '{print $2}'`
SENDER=`echo $* | awk '{print $2}'| tr [A-Z] [a-z]`
SEND_DOMAIN=`echo $SENDER | awk -F"@" '{print $2}'`
# Exit codes from <sysexits.h>
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; }

if [ "$RECIP_DOMAIN" = "$SEND_DOMAIN" ]; then
/usr/bin/altermime --input=in.$$ \
                   --disclaimer=/opt/zimbra/postfix/conf/disclaimers/emptydisclaimer.txt \
                   --disclaimer-html=/opt/zimbra/postfix/conf/disclaimers/emptydisclaimer.txt  \
                   --xheader="X-Copyrighted-Material:" || \
                    { echo Message content rejected; exit $EX_UNAVAILABLE; }

elif [ "$SEND_DOMAIN" = "$LOCAL_DOMAIN2" ]; then
/usr/bin/altermime --input=in.$$ \
                   --disclaimer=/opt/zimbra/postfix/conf/disclaimers/domain2.txt \
                   --disclaimer-html=/opt/zimbra/postfix/conf/disclaimers/domain2.txt \
                   --xheader="X-Copyrighted-Material: Please visit http://www.domain2.com/privacy.htm" || \
                   { echo Message content rejected; exit $EX_UNAVAILABLE; }

elif [ "$SEND_DOMAIN" = "$LOCAL_DOMAIN1" ]; then

/usr/bin/altermime --input=in.$$ \
                   --disclaimer=/opt/zimbra/postfix/conf/disclaimers/domain1.txt \
                   --disclaimer-html=/opt/zimbra/postfix/conf/disclaimers/domain1.txt \
                   --xheader="X-Copyrighted-Material: Please visit http://www.domain1.com/privacy.htm" || \
                    { echo Message content rejected; exit $EX_UNAVAILABLE; }

else


/usr/bin/altermime --input=in.$$ \
                   --disclaimer=/opt/zimbra/postfix/conf/disclaimers/emptydisclaimer.txt \
                   --disclaimer-html=/opt/zimbra/postfix/conf/disclaimers/emptydisclaimer.txt \
                   --xheader="X-Copyrighted-Material: " || \
                    { echo Message content rejected; exit $EX_UNAVAILABLE; }


fi

$SENDMAIL -i "$@" <in.$$
exit $?



Addition by:
Rajesh Kodali, reformatted by T. Paier
Grant Haywood ( alternate ports )




--
Daniel Eugenin M.
IT Linux Ltda.

Verified Against: Date Created: 10/1/2006
Article ID: http://wiki.zimbra.com/index.php?title=Adding_a_disclaimer_(altermime)_or_footer Date Modified: 03/20/2012
Personal tools