Mercurial > hgrepos > hgweb.cgi > s4
annotate sendmultipart.sh @ 672:4d580bd8c47f
Add charset option to text/plain part header
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Tue, 12 May 2020 11:31:50 +0900 |
parents | ae4dcd28fd39 |
children | c4beaec80322 |
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 | |
672
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
7 # Last modified Tue May 12 11:29:54 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' | |
671 | 24 -r ReplyTo Set Reply-to: header to \`ReplyTo' |
97 | 25 _EOU_ |
26 exit 0 | |
27 } | |
28 | |
29 conf=~/.sendmultipart | |
30 verbose=0 | |
31 hgid='$HGid$' | |
32 mailer=`echo $hgid|cut -d' ' -f2,3,4` | |
33 | |
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="" | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
43 nl=" |
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
44 " |
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
45 rcptheader="" |
97 | 46 |
47 [ -f $conf ] && . $conf # read rc file | |
48 | |
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`" ;; | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
55 -r) shift; REPLYTO="$1" ;; |
97 | 56 -f) shift; from="From: $1" ;; |
57 -v) verbose=1 ;; | |
651 | 58 -h) usage ;; # -h helpオプション |
97 | 59 --) shift; break ;; |
651 | 60 *) break ;; # -で始まらないものが来たら即処理突入 |
97 | 61 esac |
62 shift | |
63 done | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
64 rcptheader=`echo $rcpts|tr ' ' '\n'|sort -u|sed 's/^/To: /g'` |
97 | 65 plainheader="Content-Type: text/plain; charset=$textcharset |
66 Content-Transfer-Encoding: 7bit" | |
67 | |
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 | |
672
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
79 Content-Type: text/plain; charset=$coding |
97 | 80 Content-Disposition: inline; filename="$filename" |
81 Content-Transfer-Encoding: $encoding | |
82 | |
83 EOF | |
84 $cat $1 | |
85 } | |
86 | |
87 # Begin procedure | |
88 if [ x"$rcpts" = x"" ]; then | |
89 sendmail="cat" | |
90 else | |
91 sendmail="sendmail" | |
92 fi | |
670 | 93 body=`nkf -dj` # Convert stdin to iso-2022-jp |
97 | 94 |
95 # Generate contents | |
96 ( cat<<EOF | |
661
14a7c23f3f06
Allow supplemental rcpt address and file attachment in DM in grpAction
HIROSE Yuuji <yuuji@gentei.org>
parents:
651
diff
changeset
|
97 ${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
|
98 ${REPLYTO:+Reply-to: $REPLYTO$nl}Subject: ${subject:-$*} |
97 | 99 $ctheader |
100 Mime-Version: 1.0 | |
101 X-Mailer: $mailer | |
102 $from | |
103 | |
104 --$boundary | |
105 $plainheader | |
106 | |
107 EOF | |
108 echo "$body" | |
109 echo | |
110 for file in "$@"; do | |
111 echo "--$boundary" | |
672
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
112 ct=`file --mime-type - < "$file" | cut -d' ' -f2` |
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
113 case "$ct" in |
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
114 [Tt]ext/[Pp]lain*) |
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
115 cattextwithheader "$file" |
97 | 116 ;; |
117 *) | |
672
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
118 echo "Content-Type: $ct" |
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
119 fn=${file##*/} |
97 | 120 echo "Content-Transfer-Encoding: base64" |
672
4d580bd8c47f
Add charset option to text/plain part header
HIROSE Yuuji <yuuji@gentei.org>
parents:
671
diff
changeset
|
121 echo "Content-Disposition: inline; filename=\"$fn\"" |
97 | 122 echo |
123 $base64 $file | |
124 ;; | |
125 esac | |
126 echo | |
127 done | |
128 echo "--${boundary}--" | |
129 ) | $sendmail $rcpts | |
130 | |
131 exit 0 |