s4

view sendmultipart.sh @ 494:6906c140431a

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