s4

view sendmultipart.sh @ 1037:634fee6a6bd2

Add row number to title attribute after sort.
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 06 Mar 2024 09:55:20 +0900
parents 4d580bd8c47f
children
line source
1 #!/bin/sh
2 # 愛
3 # send multipart message via email
4 # (C)2012,2015 by HIROSE Yuuji [yuuji(at)yatex.org]
5 # You can obtain the latest version of this script from:
6 # http://www.gentei.org/~yuuji/software/sendmultipart.sh
7 # Last modified Thu May 14 07:31:16 2020 on firestorm
8 #
9 # Typical usage:
10 # echo "Hi, here's photo I've taken. Enjoy" | \
11 # sendmultipart.sh -t rcpt1@example.com,rcpt2@example.org \
12 # -s "Photo of party" -f myself@example.net photo*.jpg
14 myname=`basename $0`
15 usage () {
16 cat<<_EOU_
17 $myname: Send multipart message via email
18 Usage: $0 -t recipient [options] file(s)
19 -t ToAddress Recipient address.
20 Multiple -t option and/or Multiple ToAddresses
21 delimited by comma are acceptable.
22 -s Subject Set subject to \`Subject'
23 -f FromAddress Set From: header to \`FromAddress'
24 -r ReplyTo Set Reply-to: header to \`ReplyTo'
25 _EOU_
26 exit 0
27 }
29 conf=~/.sendmultipart
30 verbose=0
31 hgid='$HGid$'
32 mailer=`echo $hgid|cut -d' ' -f2,3,4`
34 base64byuu() {
35 uuencode -m $1 < $1 | tail +2
36 }
37 base64=${BASE64:-base64byuu}
38 boundary="${mailer}_`date +%Y%m%d,%H%M%Sx`"
39 ctheader="Content-Type: Multipart/Mixed;
40 boundary=\"$boundary\""
41 textcharset=iso-2022-jp
42 rcpts=""
43 nl="
44 "
45 rcptheader=""
47 [ -f $conf ] && . $conf # read rc file
49 while [ x"$1" != x"" ]; do
50 case "$1" in
51 -t) shift;
52 rcpts="$rcpts${rcpts:+ }`echo $1|tr , ' '`"
53 ;;
54 -s) shift; subject="`echo $1|nkf -M`" ;;
55 -r) shift; REPLYTO="$1" ;;
56 -f) shift; from="From: $1" ;;
57 -v) verbose=1 ;;
58 -h) usage ;; # -h helpオプション
59 --) shift; break ;;
60 *) break ;; # -で始まらないものが来たら即処理突入
61 esac
62 shift
63 done
64 rcptheader=${SMAIL_TO:-`echo $rcpts|tr ' ' '\n'|sort -u|tr '\n' ', '`}
65 plainheader="Content-Type: text/plain; charset=$textcharset
66 Content-Transfer-Encoding: 7bit"
68 tolower() {
69 tr '[A-Z]' '[a-z]'
70 }
71 cattextwithheader() {
72 coding=`nkf -g $1|cut -d' ' -f1`
73 case `echo $coding | tolower` in
74 iso-2022-jp) encoding=7bit cat=cat;;
75 *) encoding=base64 cat="$base64" ;;
76 esac
77 filename=`echo $1|nkf -M`
78 cat<<EOF
79 Content-Type: text/plain; charset=$coding
80 Content-Disposition: inline; filename="$filename"
81 Content-Transfer-Encoding: $encoding
83 EOF
84 $cat $1
85 }
87 # Begin procedure
88 if [ x"$rcpts" = x"" ]; then
89 sendmail="cat"
90 else
91 sendmail="sendmail"
92 fi
93 body=`nkf -dj` # Convert stdin to iso-2022-jp
95 # Generate contents
96 ( cat<<EOF
97 To: ${rcptheader:-[Not specified]}
98 ${REPLYTO:+Reply-to: $REPLYTO$nl}Subject: ${subject:-$*}
99 $ctheader
100 Mime-Version: 1.0
101 X-Mailer: $mailer
102 $from
104 --$boundary
105 $plainheader
107 EOF
108 echo "$body"
109 echo
110 for file in "$@"; do
111 echo "--$boundary"
112 ct=`file --mime-type - < "$file" | cut -d' ' -f2`
113 case "$ct" in
114 [Tt]ext/[Pp]lain*)
115 cattextwithheader "$file"
116 ;;
117 *)
118 echo "Content-Type: $ct"
119 fn=${file##*/}
120 echo "Content-Transfer-Encoding: base64"
121 echo "Content-Disposition: inline; filename=\"$fn\""
122 echo
123 $base64 $file
124 ;;
125 esac
126 echo
127 done
128 echo "--${boundary}--"
129 ) | $sendmail $rcpts
131 exit 0