]> diplodocus.org Git - nmh/blobdiff - uip/mhmail
Replace `if (p) free(p)' with `mh_xfree(p)'.
[nmh] / uip / mhmail
index ffc51298d2c619120eb2048a331f89be9b8ddeb0..27695709a287ae0772c1f433d05ac300293e1857 100755 (executable)
@@ -48,6 +48,13 @@ finddir() {
   esac
 }
 
   esac
 }
 
+help() {
+  printf '%s\n' "$usage"
+  #### Print the nmh intro text.
+  ${nmhbindir}/mhparam -help | sed -n -e '/^$/,$p'
+  exit
+}
+
 #### Convenience function to allow concise code below.
 die() {
     [ $# -gt 0 ]  &&  printf '%s\n' "$1" >&2
 #### Convenience function to allow concise code below.
 die() {
     [ $# -gt 0 ]  &&  printf '%s\n' "$1" >&2
@@ -57,7 +64,7 @@ die() {
 
 bindir=`finddir $0`
 nmhbindir=`cd "$bindir" && pwd`
 
 bindir=`finddir $0`
 nmhbindir=`cd "$bindir" && pwd`
-nmhlibdir=`$nmhbindir/mhparam libdir`
+nmhlibexecdir=`$nmhbindir/mhparam libexecdir`
 case `printf 'OK\n' | tail -n 1 2>&1` in
   OK) tail='tail -n ' ;;
   *)  tail='tail -' ;;
 case `printf 'OK\n' | tail -n 1 2>&1` in
   OK) tail='tail -n ' ;;
   *)  tail='tail -' ;;
@@ -127,7 +134,7 @@ for arg in "$@"; do
     -f|-fr|-fro|-from) mhmailswitch=1; fromarg=1 ;;
     -hea|-head|-heade|-header|-headerf|-headerfi|-headerfie|-headerfiel|\
 -headerfield) mhmailswitch=1; headerfieldarg=1 ;;
     -f|-fr|-fro|-from) mhmailswitch=1; fromarg=1 ;;
     -hea|-head|-heade|-header|-headerf|-headerfi|-headerfie|-headerfiel|\
 -headerfield) mhmailswitch=1; headerfieldarg=1 ;;
-    -hel|-help) printf '%s\n' "$usage"; exit ;;
+    -hel|-help) help ;;
     -nose|-nosen|-nosend) mhmailswitch=1; sendsw=0 ;;
     -p|-pr|-pro|-prof|-profi|-profil|-profile) mhmailswitch=1; use_send=1 ;;
     -resend) die 'mhmail: did you mean -resent instead of -resend?' ;;
     -nose|-nosen|-nosend) mhmailswitch=1; sendsw=0 ;;
     -p|-pr|-pro|-prof|-profi|-profil|-profile) mhmailswitch=1; use_send=1 ;;
     -resend) die 'mhmail: did you mean -resent instead of -resend?' ;;
@@ -189,7 +196,7 @@ if [ "$tolist"x = x ]; then
   die 'Usage: mhmail [-t(o)] addrs ... [switches]'
 fi
 if [ "$from"x = x ]; then
   die 'Usage: mhmail [-t(o)] addrs ... [switches]'
 fi
 if [ "$from"x = x ]; then
-  from=`${nmhlibdir}/ap -format '%(localmbox)' 0`
+  from=`${nmhlibexecdir}/ap -format '%(localmbox)' 0`
 fi
 
 #### Check for missing mandatory arguments.
 fi
 
 #### Check for missing mandatory arguments.
@@ -215,9 +222,11 @@ fi
 #### .orig file, so it will remove them, too.
 umask 077
 tmpdir="${MHTMPDIR:-${TMPDIR:-`$nmhbindir/mhpath +`}}"
 #### .orig file, so it will remove them, too.
 umask 077
 tmpdir="${MHTMPDIR:-${TMPDIR:-`$nmhbindir/mhpath +`}}"
-tmpfile="$tmpdir/mhmail$$"
+tmpfilename=`cd "$tmpdir"  &&  "${nmhlibexecdir}/mkstemp" -p mhmail`
+[ $? -ne 0 ]  &&  die "mhmail: failed to create temporary file in $tmpdir"
+tmpfile="$tmpdir/$tmpfilename"
 backup_char=`"$nmhbindir"/mhparam sbackup`
 backup_char=`"$nmhbindir"/mhparam sbackup`
-tmpfilebackup="'$tmpdir'/${backup_char}mhmail$$*"
+tmpfilebackup="$tmpdir/${backup_char}${tmpfilename}*"
 tmpfileresent=
 
 message_file=
 tmpfileresent=
 
 message_file=
@@ -234,7 +243,8 @@ else
     #### When resending with send, tmpfile will just contain the
     #### Resent- header fields.  "$tmpfileresent" will contain
     #### the message that is being resent.
     #### When resending with send, tmpfile will just contain the
     #### Resent- header fields.  "$tmpfileresent" will contain
     #### the message that is being resent.
-    tmpfileresent="$tmpdir/mhmail-resent$$"
+    tmpfileresent=`"${nmhlibexecdir}/mkstemp" -d "$tmpdir" -p mhmail-resent`
+    [ $? -ne 0 ]  &&  die "mhmail: failed to create temporary file in $tmpdir"
     mhdist=1; export mhdist
     mhaltmsg=$tmpfileresent; export mhaltmsg
     message_file="$tmpfileresent"
     mhdist=1; export mhdist
     mhaltmsg=$tmpfileresent; export mhaltmsg
     message_file="$tmpfileresent"
@@ -289,7 +299,7 @@ else
     post_or_send="$nmhbindir/send"
   fi
 
     post_or_send="$nmhbindir/send"
   fi
 
-  if "$post_or_send" "$tmpfile" $postsendargs; then
+  if "$post_or_send" $postsendargs "$tmpfile"; then
     exit
   else
     status=$?
     exit
   else
     status=$?