Mercurial > hgrepos > hgweb.cgi > s4
annotate sendmultipart.sh @ 584:1974f3bce999
Add padding to slant font (td.repl em)
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sat, 27 Jul 2019 08:54:43 +0900 |
parents | db840ea6e347 |
children | d764faf9194c |
rev | line source |
---|---|
97 | 1 #!/bin/sh |
2 # send multipart message via email | |
98
70de8824f27e
sendmultipart.sh added to this repo.
HIROSE Yuuji <yuuji@gentei.org>
parents:
97
diff
changeset
|
3 # (C)2012,2015 by HIROSE Yuuji [yuuji(at)yatex.org] |
97 | 4 # You can obtain the latest version of this script from: |
5 # http://www.gentei.org/~yuuji/software/sendmultipart.sh | |
323
db840ea6e347
Eliminate filename for "file" command befause of spaces in filenames.
HIROSE Yuuji <yuuji@gentei.org>
parents:
99
diff
changeset
|
6 # Last modified Fri Oct 21 10:37:19 2016 on firestorm |
97 | 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 | |
12 | |
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 } | |
26 | |
27 conf=~/.sendmultipart | |
28 verbose=0 | |
29 hgid='$HGid$' | |
30 mailer=`echo $hgid|cut -d' ' -f2,3,4` | |
31 | |
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="" | |
42 | |
43 [ -f $conf ] && . $conf # read rc file | |
44 | |
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" | |
62 | |
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 | |
77 | |
78 EOF | |
79 $cat $1 | |
80 } | |
81 | |
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 | |
89 | |
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 | |
98 | |
99 --$boundary | |
100 $plainheader | |
101 | |
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 *) | |
99 | 112 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
|
113 file --mime-type - < "$file" | cut -d' ' -f2 |
97 | 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 | |
124 | |
125 exit 0 |