#!/bin/sh # # fake-mhsend -- pretend to be the MH send program # # Pretend to be the MH send program and collect the out going mail. # Which is passed to the filter script given in your ".mh_profile" to # edit/filter (EG: append signature) that mail, before it is forwarded # on to the real send program. # # NOTE: this program does not in itself do anthing to the mail, just # allows you to write your own simple outgoing mail filter program. # It is completely controled by the .mh_profile and sould only require # editing if the filter has special requirements (eg: was -mime option # given). # # The mail filter used should allow one option [-v] for verbose! # # My own filter reads the outgoing mail for special markers to select # specific signatures from a signature archive, or just pick one at # random. It also adds a X-Face to the mail and in the future possibily # allow mime encoding for my voice or other such wonders. # # Anthony Thyssen 19 March 1998 # # ------------ # # To use this wrapper "fake-mhsend" is added to your ".mh_profile" with # sendproc: fake-mhsend # mail-filter: {mail filter program you want to use} # realsend: send # fake-mhsend: {send option you like} # send: # # These options are in order # sendproc: Tell MH to use this program for sending mail (in your PATH) # mail-filter: The mail filter (Usage: filter [-v] [file]) # you want this program to filter outgoing mail through. # EG: append signature, add X-Face etc... # realsend: What program is the real MH send command to use # fake-mhsend: Options to this program (to pass to real send program) # send: MUST BE EMPTY! # Ensure send has NO internal user options, any such options # should be added to "fake-mhsend" or unexpected results could # occur. Particularly with options like ``-push''. # # WARNING: ExMH user must re-read the .mh_profile for it to take effect. # # This program is of medium complexity and assumes the following call # structure, but should work with any send options.... # * From ``What Now?'' sends arguments are (file is last item) # send {draftfilepath} # * From ExMH the sendmail call is # send -draftf +drafts -draftm {mesgnum} # # --------------------------- # --- defaults and programs --- # Discover where this shell script program resides # This is a standard ritual for my shell scripts. # currently the only thing of importance is PROGNAME for reading # mh_profile options for this program correctly. ORIGDIR=`pwd` # original directory (builtin) PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path PROGDIR=`dirname $PROGNAME` # extract directory of program PROGNAME=`basename $PROGNAME` # base name of program (for options) cd $PROGDIR # go to that directory PROGDIR=`pwd` # remove any symbolic link parts cd $ORIGDIR # return to where we were mailfilter=`mhparam mail-filter` # mail filter to use realsend=`mhparam realsend` # user selected send program [ ! "$realsend" ] && realsend=send # default send program # --- Read the complex send arguments --- # This was extracted from the "send" source! Arrrgghhh... # prepend the ".mh_profile" options for this program # NOTE: the -- is required for some shells for thsi set to work properly # but with other shells it is included into argument list so we check. set -$- -- `mhparam $PROGNAME` "$@" [ "X$1" = "X--" ] && shift # The major arguments and options sendargs="" draft="" draftf="" draftm="" while [ $# -gt 0 ]; do arg="$1"; shift case "$arg" in # # just pass on these options (no option argument) -debug | -draft | -encrypt | -noencrypt | -nofilter | \ -format | -noformat | -forw* | -noforw* | -mime | -nomime | \ -msgid | -nomsgid | -uniq* | -nouniq* | -watch | -nowatch | \ -mail | -saml | -send | -soml | -snoop \ ) # just pass on these options sendargs="$sendargs $arg" ;; # # just pass on these options (one option argument) -alias | -filter | -width | -client | -server \ ) # pass on these options with single argument sendargs="$sendargs $arg $1"; shift ;; # # these arguments we have to worry about especially -draftf* ) draftf="$1" # what draft folder sendargs="$sendargs $arg $1"; shift ;; -draftm* ) draftm="$1" # message in draft folder sendargs="$sendargs $arg $1"; shift ;; -nodraftf* ) draftf="" # cancel any draft folder sendargs="$sendargs $arg" ;; -help) NOFILTER=true # don't filter mail! sendargs="$sendargs $arg" ;; -verbose ) VERBOSE=true # be verbose sendargs="$sendargs $arg" ;; -noverbose ) VERBOSE='' # do NOT be verbose sendargs="$sendargs $arg" ;; # Backgrounding send cound stuff up this script unless we handly it -push ) BACKGROUND=true ;; # note, but do not pass -nopush ) BACKGROUND="" ;; # turn it off again # # What is left? # -*) echo >&2 "ERROR: fake-mhsend: unknown option \"$arg\" -- ABORTING" exit 1 ;; *) draft="$arg" # Presumably the draft file number (don't auto pass) # This is the item we most want, and take all this trouble to find! # it is also probably the last item and we will force it to be last. # Lets make sure that it is the last item! esac done # force non background processing # NOTE draft argument should be empty if -draftf method is used! sendargs="$sendargs -nopush $draft" if [ "$draft" -a "$draftf" ]; then echo >&2 "ERROR: fake-mhsend: Both conficting options! -- ABORTING" exit 1 fi if [ "$draftf" -a -z "$draftm" ]; then echo >&2 "ERROR: fake-mhsend: Missing -draftm option! -- ABORTING" exit 1 fi if [ -z "$draft" -a "$draftf" -a "$draftm" ]; then draft="`mhpath $draftf $draftm`" fi if [ ! -f "$draft" ]; then echo >&2 "ERROR: Unable to location draft mail \"$draft\"" exit 1; fi # ------- Do the Real Work --------- if [ "$NOFILTER" ]; then [ "$VERBOSE" ] && echo >&2 "Fake-mhsend: no filter -- just passing mail through" exec $realsend $sendargs ${BACKGROUND:+'&'} exit 0 fi # main job as a proceedure to allow us to background it filter_send() { [ "$VERBOSE" ] && echo "Filtering Mail : $mailfilter" # Move original mail to a backup and replace it with the filtered version. cp -p $draft $draft.orig # copy so original permissions are retained $mailfilter ${VERBOSE:+'-v'} $draft.orig > $draft if [ ! -s $draft ]; then echo >&2 "Mail filter failed" exit 1 fi [ "$VERBOSE" ] && echo "Mailing Filtered Mail to \"$realsend\"" $realsend $sendargs if [ -f $draft ]; then # IS draft file still present? [ "$VERBOSE" ] && echo "Clean up after Mailing -- restoring original" mv $draft.orig $draft # THEN return original unfiltered draft! #rm -f $draft.orig # alturnative just remove original else [ "$VERBOSE" ] && echo "Clean up after Mailing -- removing original" rm -f $draft.orig # filtered mail was removed -- remove original fi } # Do the job -- background it if required #filter_send ${BACKGROUND:+'&'} ( filter_send & ) & # ------------