Admin/pmail
changeset 14034 55ba81e3502b
parent 13321 70a5d5fc081a
child 14036 fb6040d4bbf8
     1.1 --- a/Admin/pmail	Fri May 16 16:35:36 2003 +0200
     1.2 +++ b/Admin/pmail	Sun May 18 15:15:13 2003 +0200
     1.3 @@ -4,16 +4,20 @@
     1.4  # Author: Gerwin Klein, TU Muenchen
     1.5  # License: GPL (GNU GENERAL PUBLIC LICENSE)
     1.6  #
     1.7 -# DESCRIPTION: send email platform independently.
     1.8 +# DESCRIPTION: send email with text attachments.
     1.9 +# (works for "mail" command of SunOS 5.8)
    1.10 +#
    1.11  
    1.12  PRG="$(basename "$0")"
    1.13  
    1.14 +MIME_BOUNDARY="==PM_=_37427935"
    1.15 +
    1.16  function usage()
    1.17  {
    1.18    echo
    1.19 -  echo "Usage: $PRG subject recipient body"
    1.20 +  echo "Usage: $PRG subject recipient <body> [<attachments>]"
    1.21    echo
    1.22 -  echo "  Send email platform independently. Body is a file."
    1.23 +  echo "  Send email with text attachments. <body> is a file."
    1.24    echo
    1.25    exit 1
    1.26  }
    1.27 @@ -24,33 +28,68 @@
    1.28    exit 2
    1.29  }
    1.30  
    1.31 +#
    1.32 +# print_attachment <file>
    1.33 +#
    1.34 +# print mime "encoded" <file> to stdout (text/plain, 8bit)
    1.35 +#
    1.36 +function print_attachment()
    1.37 +{
    1.38 +    local FILE=$1
    1.39 +    local NAME=${FILE##*/}
    1.40 +
    1.41 +    cat <<EOF
    1.42 +$MIME_BOUNDARY
    1.43 +Content-Type: text/plain
    1.44 +Content-Transfer-Encoding: 8bit
    1.45 +Content-Disposition: attachment; filename="$NAME"
    1.46 +
    1.47 +EOF
    1.48 +    cat $FILE
    1.49 +}
    1.50 +
    1.51 +
    1.52 +#
    1.53 +# print_body subject <message-file> [<attachments>]
    1.54 +#
    1.55 +# prints mime "encoded" message with text attachments to stdout
    1.56 +#
    1.57 +function print_body()
    1.58 +{
    1.59 +    local SUBJECT=$1
    1.60 +    local BODY=$2
    1.61 +    shift 2
    1.62 +
    1.63 +    cat <<EOF
    1.64 +Subject: $SUBJECT
    1.65 +Mime-Version: 1.0
    1.66 +Content-Type: multipart/mixed; boundary="$MIME_BOUNDARY"
    1.67 +
    1.68 +$MIME_BOUNDARY
    1.69 +Content-Type: text/plain
    1.70 +Content-Transfer-Encoding: 8bit
    1.71 +
    1.72 +EOF
    1.73 +    cat $BODY
    1.74 +
    1.75 +    for a in $@; do print_attachment $a; done
    1.76 +
    1.77 +    echo "$MIME_BOUNDARY"
    1.78 +}
    1.79 +
    1.80  ## main
    1.81  
    1.82  # argument checking
    1.83  
    1.84  [ "$1" = "-?" ] && usage
    1.85 -[ "$#" != "3" ] && usage
    1.86 +[ "$#" -lt "3" ] && usage
    1.87  
    1.88  SUBJECT="$1"
    1.89  TO="$2"
    1.90  BODY="$3"
    1.91  
    1.92 +shift 3
    1.93 +
    1.94  [ -r "$BODY" ] || fail "could not read $BODY"
    1.95  
    1.96 -case `uname` in
    1.97 -    linux*|Linux*)
    1.98 -    mail -s "$SUBJECT" "$TO" < "$BODY"
    1.99 -    ;;
   1.100 -
   1.101 -    SunOS*)
   1.102 -    mail -t "$TO" <<EOF
   1.103 -Subject: $SUBJECT
   1.104 -
   1.105 -`cat $BODY`
   1.106 -EOF
   1.107 -    ;;
   1.108 -
   1.109 -    *)  
   1.110 -    fail "unkown platform"
   1.111 -    ;;
   1.112 -esac
   1.113 +print_body "$SUBJECT" "$BODY" $@ | mail -t "$TO"