Mercurial > hgrepos > hgweb.cgi > s4
annotate sendmultipart.sh @ 670:93e6e883c677
CR+LF -> LF
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 12 May 2020 10:56:12 +0900 |
parents | 14a7c23f3f06 |
children | ae4dcd28fd39 |
rev | line source |
---|---|
97 | 1 #!/bin/sh |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
2 # 愛 |
97 | 3 # send multipart message via email |
98
70de8824f27e
sendmultipart.sh added to this repo.
HIROSE Yuuji <yuuji@gentei.org>
parents:
97
diff
changeset
|
4 # (C)2012,2015 by HIROSE Yuuji [yuuji(at)yatex.org] |
97 | 5 # You can obtain the latest version of this script from: |
6 # http://www.gentei.org/~yuuji/software/sendmultipart.sh | |
670 | 7 # Last modified Tue May 12 10:50:45 2020 on firestorm |
97 | 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 | |
13 | |
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 _EOU_ | |
25 exit 0 | |
26 } | |
27 | |
28 conf=~/.sendmultipart | |
29 verbose=0 | |
30 hgid='$HGid$' | |
31 mailer=`echo $hgid|cut -d' ' -f2,3,4` | |
32 | |
33 base64byuu() { | |
34 uuencode -m $1 < $1 | tail +2 | |
35 } | |
36 base64=${BASE64:-base64byuu} | |
37 boundary="${mailer}_`date +%Y%m%d,%H%M%Sx`" | |
38 ctheader="Content-Type: Multipart/Mixed; | |
39 boundary=\"$boundary\"" | |
40 textcharset=iso-2022-jp | |
41 rcpts="" | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
42 nl=" |
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
43 " |
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
44 rcptheader="" |
97 | 45 |
46 [ -f $conf ] && . $conf # read rc file | |
47 | |
48 while [ x"$1" != x"" ]; do | |
49 case "$1" in | |
50 -t) shift; | |
51 rcpts="$rcpts${rcpts:+ }`echo $1|tr , ' '`" | |
52 ;; | |
53 -s) shift; subject="`echo $1|nkf -M`" ;; | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
54 -r) shift; REPLYTO="$1" ;; |
97 | 55 -f) shift; from="From: $1" ;; |
56 -v) verbose=1 ;; | |
651 | 57 -h) usage ;; # -h helpオプション |
97 | 58 --) shift; break ;; |
651 | 59 *) break ;; # -で始まらないものが来たら即処理突入 |
97 | 60 esac |
61 shift | |
62 done | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
63 rcptheader=`echo $rcpts|tr ' ' '\n'|sort -u|sed 's/^/To: /g'` |
97 | 64 plainheader="Content-Type: text/plain; charset=$textcharset |
65 Content-Transfer-Encoding: 7bit" | |
66 | |
67 tolower() { | |
68 tr '[A-Z]' '[a-z]' | |
69 } | |
70 cattextwithheader() { | |
71 coding=`nkf -g $1|cut -d' ' -f1` | |
72 case `echo $coding | tolower` in | |
73 iso-2022-jp) encoding=7bit cat=cat;; | |
74 *) encoding=base64 cat="$base64" ;; | |
75 esac | |
76 filename=`echo $1|nkf -M` | |
77 cat<<EOF | |
78 Content-Type: text/plain; charset="$coding" | |
79 Content-Disposition: inline; filename="$filename" | |
80 Content-Transfer-Encoding: $encoding | |
81 | |
82 EOF | |
83 $cat $1 | |
84 } | |
85 | |
86 # Begin procedure | |
87 if [ x"$rcpts" = x"" ]; then | |
88 sendmail="cat" | |
89 else | |
90 sendmail="sendmail" | |
91 fi | |
670 | 92 body=`nkf -dj` # Convert stdin to iso-2022-jp |
97 | 93 |
94 # Generate contents | |
95 ( cat<<EOF | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
96 ${rcptheader:-To: [Not specified]} |
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
97 ${REPLYTO:+Reply-to: $REPLYTO$nl}Subject: ${subject:-$*} |
97 | 98 $ctheader |
99 Mime-Version: 1.0 | |
100 X-Mailer: $mailer | |
101 $from | |
102 | |
103 --$boundary | |
104 $plainheader | |
105 | |
106 EOF | |
107 echo "$body" | |
108 echo | |
109 for file in "$@"; do | |
110 echo "--$boundary" | |
111 case `echo $file|tolower` in | |
112 *.txt|*.jis|*.sjis|*.euc|*.utf*) | |
113 cattextwithheader $file | |
114 ;; | |
115 *) | |
99 | 116 echo -n "Content-Type: " |
323
db840ea6e347
Eliminate filename for "file" command befause of spaces in filenames.
HIROSE Yuuji <yuuji@gentei.org>
parents:
99
diff
changeset
|
117 file --mime-type - < "$file" | cut -d' ' -f2 |
97 | 118 echo "Content-Transfer-Encoding: base64" |
119 echo "Content-Disposition: inline; filename=\"$file\"" | |
120 echo | |
121 $base64 $file | |
122 ;; | |
123 esac | |
124 echo | |
125 done | |
126 echo "--${boundary}--" | |
127 ) | $sendmail $rcpts | |
128 | |
129 exit 0 |