#!/bin/sh -b
# This is a short script for sending mail with term via smail
# The arguments are what field to use from the gcos field for the
# rom address.
#

HOME=`awk '{
  FS=":";
  split($0,argv);
  FS="@";
  split("'"$SENDER"'",sender);
  if(argv[1]==sender[1]){
    print argv[6];
} }'</etc/passwd`

SENDER_NAME="$1"
if [ "X$SENDER_NAME" = X ]; then
  SENDER_NAME="Unknown"
fi

if [ -f $HOME/.mailrc ]; then
  FROM=`awk '{
    if( $1 ~ /^[Aa][Ll][Ii][Aa][Ss]$/ && $2 ~ /^[Ff][Rr][Oo][Mm]$/ ){
      print $3;
      exit;
  };}'<$HOME/.mailrc`
fi

# Decide if we should send this or queue it
#
if /usr/local/bin/tiptest localhost ; then
  echo $FIELD $SENDER /usr/lib/sendmail -f "$FROM" -F "$SENDER_NAME" -oMr "termsmtp" -bm "$ADDR" >> /tmp/log
  if [ "X$FROM" = X ]; then
    exit -1
  fi
  /usr/lib/sendmail -f "$FROM" -F "$SENDER_NAME ($SENDER)" -oMr "termsmtp" -bm "$ADDR"
else
  if [ "X$FROM" = X ]; then
    (echo 'Subject: Bounce Bounce';
     echo '';
     echo 'You need to 'alias from YOUR-REPLY-ADDRESS' in your .mailrc file';
     echo 'Your message follows.';
     echo '';
     cat)|/usr/lib/sendmail -f "$SENDER" -F "$SENDER_NAME" -bm "$SENDER"
  else
    /usr/lib/sendmail -Q -f "$SENDER" -F "$SENDER_NAME" -bm "$ADDR"
  fi
fi
exit 0

#!/bin/sh -b
# This is a short script for sending mail with term via smail
# The arguments are what field to use for the from address
# and from address.
#

SENDER_NAME=$1
if [ "X$SENDER_NAME" = X ]; then
  SENDER_NAME=`awk '{
  FS=":";
    if($1=="'"$SENDER"'"){
      FS=",";
      split($5,a);
      print a[1];
  } }'</etc/passwd`
fi
FIELD=$2
if [ "X$FIELD" = X ]; then
  FIELD=2
fi

# Decide if we should send this or queue it
#
if /usr/local/bin/tiptest localhost ; then
  FROM=`awk '{
    FS=":";
      if($1=="'"$SENDER"'"){
        FS=",";
        if(split($5,a)>='$FIELD'){
          print a['$FIELD'];
    } } }'</etc/passwd`
  if [ "X$FROM" = X ]; then
    exit -1
  fi
  echo "$FROM" "$SENDER_NAME" "$ADDR" >> /tmp/log
  /usr/lib/sendmail -f "$FROM" -F "$SENDER_NAME" -oMr "termsmtp" -bm "$ADDR"
else
  /usr/lib/sendmail -Q -f "$SENDER" -F "$SENDER_NAME" -bm "$ADDR"
fi
exit 0

