#! /bin/sh # $Id: mysend,v 1.3 1994/09/06 12:14:16 jerry book3 $ ### mysend -- sendproc that adds signature (or anything) to mail ### Usage (in MH profile): sendproc: /xxx/yyy/mysend ## ## INSTALL THIS SCRIPT AS YOUR sendproc, whatnow WILL RUN ## IT AFTER YOU TYPE send OR push AT THE What now? PROMPT. ## THE SCRIPT PARSES ALL THE ARGUMENTS YOU TYPE AT THE ## What now? PROMPT (IF ANY) AND LOOKS FOR -signature OR ## -nosignature (OR THE ABBREVIATIONS -sig AND -nosig). ## ALSO, -face ADDS A X-Face: COMPONENT FROM THE ~/.face FILE; ## -noface STOPS THE FACE IF IT'S BEEN SET AS THE DEFAULT. ## ## IF THE SCRIPT FINDS THOSE FLAGS, IT SETS A FLAG VARIABLE; ## THE REST OF THE ARGUMENTS, INCLUDING THE DRAFT PATHNAME ## (ADDED BY whatnow) ARE PASSED TO THE *REAL* MH send COMMAND. ## ## NOTE: whatnow RUNS THIS SCRIPT; IT DOES NOT PASS THIS SCRIPT ## ANY send: ARGUMENTS FROM YOUR MH PROFILE. (YOU CAN GET mysend: ## ARGUMENTS FROM THE MH PROFILE BY USING THE mhparam SCRIPT.) ## ## BEFORE IT ADDS YOUR SIGNATURE TO THE DRAFT, mysend CHECKS ## CHECKS THE $mhdist ENVIRONMENT VARIABLE TO BE SURE YOU AREN'T ## USING dist (YOU CAN'T ADD ANY TEXT TO THE BODY OF A dist'ED ## MESSAGE). THEN IT CHECKS TO SEE WHETHER YOU WANT A SIGNATURE ## (YOU CAN HARD-CODE THE DEFAULT ON THE dosig= LINE OF THE SCRIPT, ## BY THE WAY). IF YOU DO, IT APPENDS YOUR $HOME/.signature FILE ## TO THE DRAFT WITH A LINE OF TWO DASHES (--) BEFORE. ## ## FINALLY, THE SCRIPT execS THE REAL MH send COMMAND. ## ## NOTE TO HACKERS: TABSTOPS ARE SET AT 4 IN THIS CODE ## ## NOTE: THERE SEEMS TO BE A BUG IN MH 6.7.2 (AT LEAST) THAT WON'T ## PASS THE -dist SWITCH TO THE post COMMAND IF AN EXTERNAL ## sendproc (LIKE THIS!) IS USED. THE RESULT IS ERRORS LIKE ## THESE IF YOU USE THIS sendproc DURING THE dist COMMAND: ## What now? send ## post: illegal header line -- Resent-To: ## ... ## THE mydist SHELL SCRIPT WORKS AROUND THIS PROBLEM. ## IT'S A FRONT-END dist SHELL SCRIPT THAT MAKES A ## TEMPORARY COPY OF YOUR MH PROFILE WITHOUT ITS ## sendproc: ENTRY. UGLY... BUT WORTH IT IF YOU USE dist. ## ## NOTE: IF YOU RENAME THIS, DON'T CALL send; whatnow WON'T USE IT. mh=/usr/local/mh # WHERE MH COMMANDS LIKE send LIVE doface=n # DEFAULT: NO FACE dosig=n # DEFAULT: NO SIGNATURE face=$HOME/.face # FACE FILE, INCLUDING X-Face: signature=$HOME/.signature # SIGNATURE FILE TO READ # PARSE COMMAND LINE, GRAB OUR OPTIONS. # FIRST ARGS ARE OPTIONS; LAST IS DRAFT FILENAME: while : do case "$1" in "") break ;; # ALL DONE -sig*) dosig=y ;; -nosig*) dosig=n ;; -face) doface=y ;; -noface) doface=n ;; *) args="$args $1" ;; # FOR send esac draft="$1" # EVENTUALLY THIS GETS DRAFT PATHNAME shift done # NO EDITS IF $mhdist ENVARIABLE IS 1 (DRAFT IS A dist HEADER): case "$mhdist" in 1) ;; *) # BEFORE DOING EDITS, EXIT IF DRAFT ISN'T READY: if [ ! -w "$draft" -o ! -r "$draft" ]; then echo "$0 quitting: unwritable or unreadable '$draft'" 1>&2 exit 1 fi # SET UP FOR ANY sed EDITS BY BUILDING $sedcmd EDITING COMMAND: case "$doface" in y) if [ -r "$face" ]; then # WE CAN'T KNOW IF ANY HEADER COMPONENTS ARE MULTI-LINE # OR IF MESSAGE HAS To:, cc: ETC. SO ADD FACE TO TOP: sedcmd="${sedcmd} -e '1r $face'" else echo "$0 quitting: unreadable '$face'" 1>&2 exit 1 fi ;; esac # DO ANY sed EDITS. (USE sed BECAUSE ed BOMBS ON HUGE FILES.) # CAN TEST ALL sed-EDITING VARIABLES AT ONCE (case "$var1$var2") case "$doface" in *y*) temp=/tmp/MYSEND$$ # sed COMMAND MAY HAVE QUOTES IN IT, SO USE eval: eval /bin/sed $sedcmd $draft > $temp || exit 1 /bin/cp $temp $draft || exit 1 /bin/rm -f $temp ;; esac # ADD SIGNATURE FILE: case "$dosig" in y) if [ -r "$signature" ]; then # SOME echoS CHOKE ON DASHES, SO DO IT THIS WAY: /bin/cat - "$signature" << \ENDPRESIG >> $draft || exit 1 -- ENDPRESIG else echo "$0 quitting: unreadable '$signature'" 1>&2 exit 1 fi ;; esac ;; esac if $mh/send $args then exit 0 else # send returned non-zero. If "push" command was used, # try to ring bell (by making a control-G) and print warning # (there's no second chance; "whatnow" always exits after "push"). case "$args" in *-push*) /bin/cat << END 1>&2 ******************************************************* `echo x | /bin/tr x '\07'`$0 WARNING: $mh/send $args returned a non-zero status. Check for an unsent draft. ******************************************************* END ;; esac # If "push" not used, this will make "whatnow" prompt again: exit 1 fi
[Table of Contents] [Index] [Return to Explanation of mysend] [The mydist Shell Script]
This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.
Suggestions are welcome: Jerry Peek <jerry@ora.com>
HIVE: All information for read only. Please respect copyright! |