Perhaps not a procmail question per-se, but there may well be a
procmail solution.
I've set up a simple remailer (kinda like the anonymous remailers, but
it's intended for internal use and it's not anonymous)...the reasons
are long and details, but really aren't of much interest to the
problem at hand. The remailer treats lines until the first blank line
in the body as new headers that should be merged into the outgoing
message; this is for use with barely functional SMTP gateways.
The problem I'm having is that I can't get the postmark of the
remailed message to change. About the only thing I don't want to do
us use "procmail" for the prog mailer in /etc/sendmail.cf (this is
running on a Solaris 2.1 for x86 box, so you'll understand why I'm not
too keen on any changes :-) ).
The way things are currently (after trying all kinds of different
things) set up is as follows:
* in /etc/aliases
forwarder: forwarder: "|/usr/local/bin/procmail -f daemon \
/etc/mail/forwarder.rc"
* /etc/mail/forwarder.rc is a very simple .rc file:
----
PATH=/bin:/usr/bin:/usr/local/bin
SHELL=/bin/sh
:0
| formail -I "From " | /etc/mail/forwarder.ksh
----
* the real guts are forwarder.ksh which I've appended below.
I'd happily go for piping the message directly to
/etc/mail/forwarder.ksh, but my thought was that introducing procmail
would give me more opportunities to get the postmark the way I want
it.
So what I do I want the postmark to look like? The best would be
whatever is in the *new* "From:" line; but I'd settle for something
generic at this point like "daemon".
Thanks for any suggestions
Dan
------------------- message is author's opinion only ------------------
J. Daniel Smith <DanS(_at_)bristol(_dot_)com> http://www.bristol.com/~dan
Bristol Technology B.V. +31 33 450 50 50, ...51 (FAX)
Amersfoort, the Netherlands {info,jobs}(_at_)bristol(_dot_)com
-----
#!/bin/ksh
#
# Takes a mail message on stdin, treats the initial body as headers to
# supersede in the original message. Munges it all together and
# resends the message.
#
# Intended for use with lamo SMTP mail system like Lotus Notes
#
PATH=$PATH:/usr/ucb:/usr/local/bin
#me=`basename $0`
# something funky that seemingly results from SUID bit being set
mypath="/etc/mail/forwarder.ksh"
me=`basename $mypath`
tmpdir=${TMPDIR:-/tmp}
if [ "$1" != "" ]; then
# echo "second pass 1 - $$, $1"
pid=$1
else
# echo "first pass 1 - $$"
pid=$$
fi
tmp=$tmpdir/$me.$pid
body=$tmpdir/body_$me.$pid
newhdr=$tmpdir/newhdr_$me.$pid
loop="$me(_at_)`hostname`"
if [ "$1" = "" ]; then
# echo "first pass 2 - $$"
cat > $tmp
formail -I "" < $tmp > $body
formail -f -X "" < $body > $newhdr
if [ ! -s $newhdr ]; then
rm -f $tmp $body $newhdr
exit 67 # EX_NOUSER
fi
if [ `formail -X "" < $tmp | grep -c "X-Loop: $loop"` -ne 0 ]; then
rm -f $tmp $body $newhdr
exit 69 # EX_UNAVAILALBE
fi
# it's easier to to the "read" below from stdin
# but, to keep this all in one script, call myself again
# echo "cat $newhdr | exec $mypath $pid"
cat $newhdr | exec $mypath $pid
fi
# why? exec above should make this never happen...
# OK in KSH, but not SH??
#if [ "$$" != "$pid" ]; then
# echo "second pass 2 - $$, $pid"
fields="header"
ifs=$IFS
cmd=""
while eval read $fields
do
if [ "$header" != "" ]; then
cmd="$cmd -i '$header'"
fi
done
IFS=$ifs
tmp2=$tmpdir/2$me.$pid
(formail -X "" < $tmp; formail -I "" < $body) | \
eval formail $cmd | \
formail -I "From " -I Content-Length: \
-A "X-Forwarder: $me" -A "X-Loop: $loop" > $tmp2 && \
mv $tmp2 $tmp
# -f sets the postmark properly and more importantly causes sendmail
# to provide a correct Return-Path: header
FROM=`formail -zrtx To: < $tmp`
cat $tmp | /usr/lib/sendmail -t -oi -f "$FROM"
# cat $tmp | cat
rm -f $tmp $body $newhdr
#fi
exit 0