procmail
[Top] [All Lists]

Re: Sending later

1997-05-07 04:03:00
era eriksson writes on 7 May 1997 at 11:02:17
On Wed, 7 May 1997 09:29:23 +0200 (MET DST),
Bernard El-Hagin <sokrates(_at_)sound(_dot_)eti(_dot_)pg(_dot_)gda(_dot_)pl> 
wrote:
 Is it possible for procmail to send mail automatically at a later date
set by me? 
[...]
real headers of the message to actually send later are immediately at
the beginning of the message body.

Then you could do this:

   :0b
   * ^Subject: LATER$
   | sleep 50000 ; $SENDMAIL $SENDMAILFLAGS -t
[...]
course. The b flag makes Procmail feed only the body of the message to
the pipeline, and Sendmail will then take the first lines of the body
for a header instead.
[...]
   From you
   Subject: LATER
   Date: Wed, 7 May 1997 09:29:23 +0200 (MET DST)
   From: Bernard El-Hagin 
<sokrates(_at_)sound(_dot_)eti(_dot_)pg(_dot_)gda(_dot_)pl>
   Message-Id: 
<you(_dot_)could(_dot_)have(_dot_)already(_dot_)won--scratch(_dot_)here(_at_)sound(_dot_)eti(_dot_)pg(_dot_)gda(_dot_)pl>
   To: sokrates

   From: Bernard El-Hagin 
<sokrates(_at_)sound(_dot_)eti(_dot_)pg(_dot_)gda(_dot_)pl>
   To: procmail(_at_)informatik(_dot_)rwth-aachen(_dot_)de (those jolly 
fellows)
   Subject: I am sending this later

   Hello, 

   Body of message goes here

I've actually set something up which is quite similar to this (without
the time-delay); many anonymous remailers do the same, although they
are generally much more sophsticated.

Anyway, the technique I use is that headers at the beginning of the
body *override* those in the original message.  Unfortunately, I
couldn't figure out how to do all of this completely in "procmail", so
I used a rather ugly Korn-Shell script instead; I also couldn't figure
out how to change the envelope address (old version of sendmail?) even
with various things SUID so in the above example "you" is in the final
message instead of "sokrates(_at_)(_dot_)(_dot_)(_dot_)".

Should anybody be interested (or willing to convert this to all/mostly
procmail :-) ), here's the KSH code.

   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/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

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