procmail
[Top] [All Lists]

Re: Outgoing mail filters

1997-08-08 03:59:00
Mike A. Harris writes on 8 August 1997 at 03:32:03
Is it possible somehow to use procmail as an outgoing mail
filter?  For example, I have a bash shell script which I've

I've set this up myself recently with a shell-script wrapper around
sendmail.  If your MUA allows you to specify the MTA (I use VM in
Emacs, so nearly everything can be tweaked), you can do this just for
yourself; otherwise you'll need to be "root" and play a few games with
/usr/lib/sendmail or /etc/sendmail.

Here's what "mysendmail" looks like--suggestions for improvements most
welcome.

   Dan
------------------- message is author's opinion only ------------------
J. Daniel Smith <DanS(_at_)bristol(_dot_)com>        
http://www.bristol.com/~DanS
Bristol Technology B.V.                   +31 33 450 50 50, ...51 (FAX)
Amersfoort, The Netherlands               {info,jobs}(_at_)bristol(_dot_)com
-----
#!/bin/sh
do_my_sendmail=0
case "$*" in
  *-t*) do_my_sendmail=1; break ;;
esac

if [ $do_my_sendmail -ne 1 ]; then
  exec /usr/lib/sendmail "$@"
else
  PATH=$PATH:/bin
  tmpd=${TMPDIR:-/tmp}
  me=`basename $0`
  tmpf=$tmpd/$me$$.rc
  #
  # if this message is going off-site, make it look like it came from my
  # iName address (which gets them forwarded back to me) - but at
  # least people aren't saving away a work address.  I thought about
  # using Reply-To: instead, which would probably be better...but that
  # can do unexpected things with mailing lists depending on how the
  # list is configured and the recipient's MUA.  Only over-ride my
  # "standard" From: header since I might have already edited it
  #
  # As for PlanetAll vs. iName...I can't decide :-)  iName seems to
  # focused on just email, so it should be "better"
  #
  # Some machines in the bristol.com domain aren't configured
  # correctly and occasionally a hostname sneaks through.
  # Also, *someday* we might start using sub-domains.
  #
  cat <<\EOF > $tmpf
PATH=/bin:/usr/bin:/usr/local/bin
SHELL=/bin/sh

DEFAULT=|
EMAIL="J(_dot_)Daniel(_dot_)Smith(_at_)WriteMe(_dot_)com"
:0
* !^TO[-a-z0-9_]+@(([-a-z0-9_]+\.)?bristol)\.com
* ^From:(.*[^-a-z0-9_])?DanS(_at_)bristol\(_dot_)com 
| formail -i"From: $EMAIL (J. Daniel Smith)" | $SENDMAIL -t -oi -f $EMAIL
:E
! -t -oi
EOF
  /usr/local/bin/procmail $tmpf
#  /usr/lib/sendmail "$@"
  stat=$?
  rm -f $tmpf
  exit $stat
fi

<Prev in Thread] Current Thread [Next in Thread>