nmh-workers
[Top] [All Lists]

Re: [Nmh-workers] Sending "automatic" email

2008-04-23 16:08:54
Xavier Maillard <xma(_at_)gnu(_dot_)org> wrote on Apr 23, 2008:

I am trying to figure out how, given the To, Subject and body of message, to 
generate a complete mail draft ready to shoot.

I'm not quite sure what you are want.  But here is a shell script,
shamelessly stolen from somewhere forgotten, and modified for my
use.  It probably isn't what you want, but might be something you
can modify to do what you want.

 -NWR
  ----------------- cut here -------------
#!/bin/sh

# System dependencies

defeditor=/usr/bin/vi

istty=no
if test -t 0; then istty=yes ; fi

dotdir=${DOTDIR-${HOME-$LOGDIR}}
MHDIR=`mhpath +` 2>/dev/null
if [ $? != 0 ] ; then
  echo "MH does not appear to be available or initialized" >&2
  exit 1
fi

fcc="+outbox"

subject=
cc=
bcc=
to=

while :
do
        case $# in
        0) break ;;
        esac

        case "$1" in
        "-s") subject="$2" ; shift ;;
        "-c") case "$cc" in
                "") cc="$2" ;;
                *)  cc="$cc, $2" ;;
              esac
              shift
              ;;
        "-b") case "$bcc" in
                "") bcc="$2" ;;
                *)  bcc="$bcc, $2" ;;
              esac
              shift
              ;;
        "-d") case "$dcc" in
                "") dcc="$2" ;;
                *)  dcc="$dcc, $2" ;;
              esac
              shift
              ;;
        "-t") case "$to" in
                "") to="$2" ;;
                *)  to="$to, $2" ;;
              esac
              shift
              ;;
        "-f") case "$2" in
                +*) x=`mhpath "$2"` ;;
                *)  x=`mhpath "+$2"` ;;
              esac
              if [ -d "$x" ] ; then
                fcc="$2"
              else
                echo "folder $2 : not found" >&2
                exit 1
              fi
              shift
              ;;
        *)    case "$to" in
                "") to="$1" ;;
                *)  to="$to, $1" ;;
              esac
              ;;
        esac
        shift
done

case "$to" in
        "") echo "xmail: No 'To:' recipients" 1>&2
            exit 1
            ;;
esac

draftfile=`mhpath +drafts new`

echo "To: $to" > $draftfile
case "$cc" in
        "") ;;
        *) echo "Cc: $cc" >> $draftfile ;;
esac

case "$dcc" in
        "") ;;
        *) echo "Dcc: $dcc" >> $draftfile ;;
esac

case "$bcc" in
        "") ;;
        *) echo "Bcc: $bcc" >> $draftfile ;;
esac

case "$subject" in
        "") ;;
        *) echo "Subject: $subject" >> $draftfile ;;
esac

echo "Fcc: $fcc" >> $draftfile
echo "--------" >> $draftfile

case "$istty" in
        "no") SIZE="`wc -c < $draftfile`"
              cat >> $draftfile
              case "`wc -c < $draftfile`" in
                "$SIZE") echo "Empty message not sent" 1>&2
                         rm -f $draftfile
                         exit 1
                         ;;
              esac
              exec send -push $draftfile
              ;;
esac

echo "" >> $draftfile
echo " -NWR" >> $draftfile
exec comp -use -editor ${VISUAL-${EDITOR-$defeditor}} -draftf +drafts -draftm 
last

  ----------------- cut here -------------


_______________________________________________
Nmh-workers mailing list
Nmh-workers(_at_)nongnu(_dot_)org
http://lists.nongnu.org/mailman/listinfo/nmh-workers

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