#!/bin/sh # 愛 # send multipart message via email # (C)2012,2015,2020 by HIROSE Yuuji [yuuji(at)yatex.org] # You can obtain the latest version of this script from: # http://www.gentei.org/~yuuji/software/sendmultipart.sh # Last modified Wed Jan 3 21:38:35 2024 on firestorm # # Typical usage: # echo "Hi, here's photo I've taken. Enjoy" | \ # sendmultipart.sh -t rcpt1@example.com,rcpt2@example.org \ # -s "Photo of party" -f myself@example.net photo*.jpg myname=`basename $0` usage () { cat<<_EOU_ $myname: Send multipart message via email Usage: $0 -t recipient [options] file(s) -t ToAddress Recipient address. Multiple -t option and/or Multiple ToAddresses delimited by comma are acceptable. -c CarbonCopy Recipient address of Cc: -s Subject Set subject to \`Subject' -f FromAddress Set From: header to \`FromAddress' -r ReplyTo Set Reply-to: header to \`ReplyTo' _EOU_ exit 0 } conf=~/.sendmultipart verbose=0 hgid='$HGid: sendmultipart.sh,v 1175:217978b97599 2024-01-03 21:39 +0900 yuuji $' mailer=`echo $hgid|cut -d' ' -f2,3,4` base64byuu() { uuencode -m $1 < $1 | sed '1d;$d' } base64=${BASE64:-base64byuu} boundary="${mailer}_`date +%Y%m%d,%H%M%Sx`" ctheader="Content-Type: Multipart/Mixed; boundary=\"$boundary\"" textcharset=iso-2022-jp rcpts="" nl=" " rcptheader="" [ -f $conf ] && . $conf # read rc file while [ x"$1" != x"" ]; do case "$1" in -t) shift; rcpts="$rcpts${rcpts:+ }`echo $1|tr , ' '`" ;; -c) shift; ccs="$ccs${ccs:+ }`echo $1|tr , ' '`" ;; -s) shift; subject="`echo $1|nkf -M`" ;; -r) shift; REPLYTO="$1" ;; -f) shift; from="From: $1" ;; -v) verbose=1 ;; -h) usage ;; # -h helpオプション --) shift; break ;; *) break ;; # -で始まらないものが来たら即処理突入 esac shift done rcptheader=${SMAIL_TO:-`echo $rcpts|tr ' ' '\n'|sort -u|tr '\n' ,\ | sed 's/,$//;s/,/, /g'`} if [ -n "$ccs" ]; then ccheader=${SMAIL_CC:-`echo -n $ccs|tr ' ' '\n'|sort -u|tr '\n' ,`} CC="${nl}Cc: `echo $ccheader|sed 's/,$//;s/,/, /g'`" fi plainheader="Content-Type: text/plain; charset=$textcharset Content-Transfer-Encoding: 7bit" tolower() { tr '[A-Z]' '[a-z]' } cattextwithheader() { coding=`nkf -g $1|cut -d' ' -f1` case `echo $coding | tolower` in iso-2022-jp) encoding=7bit cat=cat;; *) encoding=base64 cat="$base64" ;; esac filename=`echo $1|nkf -M` cat<