Mercurial > hg > Applications > mh
comparison miscellany/scripts/amhmail.sh @ 0:bce86c4163a3
Initial revision
author | kono |
---|---|
date | Mon, 18 Apr 2005 23:46:02 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:bce86c4163a3 |
---|---|
1 #! /bin/sh | |
2 # | |
3 # amhmail - aliased version of mhmail(1) | |
4 # | |
5 # This program has the same syntax as does mhmail(1). The differences | |
6 # are that amhmail will do aliasing of addresses by using ali(1) which | |
7 # mhmail(1) does not do. | |
8 # | |
9 # The other difference is that amhmail will prompt you if the body of | |
10 # the message is not specified on the command line and stdin is a | |
11 # terminal. | |
12 # | |
13 # WARNING: DON'T CALL THIS FILE 'mhmail' or 'ali'! | |
14 # | |
15 # Andy Crump (andyc@inteloc) | |
16 # phone: 681-4697, MS: JF1-70 | |
17 # | |
18 | |
19 PGM="`basename $0`" | |
20 USAGE="syntax: $PGM [addrs ... [-body text] [-cc addrs ...] [-from addr] [-s su | |
21 bject] [-(help)]]" | |
22 | |
23 if [ $# -eq 0 ]; then # If no arguments, do an inc(1) | |
24 inc | |
25 exit 0 | |
26 fi | |
27 | |
28 BODY="NO BODY" | |
29 CC= | |
30 FROM= | |
31 SUBJECT= | |
32 ADDRS= | |
33 | |
34 while [ $# -ne 0 ] | |
35 do | |
36 case $1 in | |
37 -help) # Help message only | |
38 echo "$USAGE" | |
39 exit 0 | |
40 ;; | |
41 -b*) # -body option, next argument is the text | |
42 shift | |
43 BODY="$1" | |
44 if [ $# -ne 0 ]; then | |
45 shift | |
46 fi | |
47 ;; | |
48 -s*) # -subject option, next argument is the text | |
49 shift | |
50 SUBJECT="$1" | |
51 if [ $# -ne 0 ]; then | |
52 shift | |
53 fi | |
54 ;; | |
55 -c*) # -cc option, all non (-) arguments are taken | |
56 # to be cc's. | |
57 shift; | |
58 BREAK=0; | |
59 while [ $BREAK -eq 0 ] | |
60 do | |
61 case "$1" in | |
62 -*) | |
63 BREAK=1; | |
64 CC="`ali $CC`"; | |
65 continue; | |
66 ;; | |
67 *) | |
68 CC="$CC $1" | |
69 if [ $# -ne 0 ]; then | |
70 shift; | |
71 else | |
72 BREAK=1; | |
73 CC="`ali $CC`"; | |
74 continue; | |
75 fi | |
76 ;; | |
77 esac | |
78 done | |
79 ;; | |
80 -f*) # -from option, next argument is the text | |
81 shift | |
82 FROM="$1" | |
83 if [ $# -ne 0 ]; then | |
84 shift | |
85 fi | |
86 ;; | |
87 -*) # what is this?? | |
88 echo "$PGM : $1 unknown option." | |
89 echo "$USAGE" | |
90 exit 1 | |
91 ;; | |
92 *) # the addresses or garbage | |
93 if [ ! -z "$ADDRS" ]; then # if we already have the | |
94 # addresses, this must be | |
95 # garbage | |
96 echo "$USAGE" | |
97 exit 1 | |
98 fi | |
99 | |
100 BREAK=0 | |
101 while [ $BREAK -eq 0 ] | |
102 do | |
103 case "$1" in | |
104 -*) | |
105 BREAK=1 | |
106 ADDRS="`ali $ADDRS`" | |
107 continue | |
108 ;; | |
109 *) | |
110 ADDRS="$ADDRS $1" | |
111 if [ $# -ne 0 ]; then | |
112 shift | |
113 else | |
114 BREAK=1 | |
115 ADDRS="`ali $ADDRS`" | |
116 continue | |
117 fi | |
118 ;; | |
119 esac | |
120 done | |
121 ;; | |
122 esac | |
123 done | |
124 | |
125 # | |
126 # Build the command line | |
127 # | |
128 | |
129 CMDLINE="mhmail $ADDRS" | |
130 | |
131 if [ "$BODY" != "NO BODY" ]; then | |
132 CMDLINE="$CMDLINE -b \"$BODY\"" | |
133 else | |
134 if [ -t 0 ]; then # if stdin is a terminal | |
135 echo "$PGM : Body of message is being read from stdin." | |
136 echo " Please enter your message and then type ctrl-D." | |
137 echo "" | |
138 fi | |
139 fi | |
140 if [ ! -z "$CC" ]; then | |
141 CMDLINE="$CMDLINE -cc $CC" | |
142 fi | |
143 if [ ! -z "$FROM" ]; then | |
144 CMDLINE="$CMDLINE -from $FROM" | |
145 fi | |
146 if [ ! -z "$SUBJECT" ]; then | |
147 CMDLINE="$CMDLINE -subject \"$SUBJECT\"" | |
148 fi | |
149 | |
150 eval "$CMDLINE" # do it! | |
151 exit 0 |