]> diplodocus.org Git - nmh/blob - test/repl/test-convert
Don't `else' after return. Simplify control flow.
[nmh] / test / repl / test-convert
1 #!/bin/sh
2 ######################################################
3 #
4 # Test repl -convertarg
5 #
6 ######################################################
7
8 set -e
9
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname $0`/../..
12 MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
13 fi
14
15 . "${srcdir}/test/post/test-post-common.sh"
16
17 expected="$MH_TEST_DIR/test-convert$$.expected"
18 actual=`mhpath +`/draft
19
20 printf 'Local-Mailbox: recipient@example.com\n' >>"$MH"
21
22
23 #### Make sure that this works with 7-bit encoding.
24 LC_ALL=C; export LC_ALL
25
26
27 # check -convertarg with multiple parts and additional text in draft
28 start_test '-convertarg with multiple parts and additional text in draft'
29 cat >"$expected" <<'EOF'
30 From: recipient@example.com
31 To: sender@example.com
32 cc:
33 Fcc: +outbox
34 Subject: Re: test
35 Comments: In-reply-to sender@example.com
36 message dated "Thu, 11 Dec 2014 08:19:02 -0600."
37 MIME-Version: 1.0
38 Content-Type: text/plain; charset="US-ASCII"
39
40 > This is part 1.
41
42 > This is part 2.
43 EOF
44
45 cat >`mhpath new` <<'EOF'
46 From: sender@example.com
47 To: recipient@example.com
48 Subject: test
49 Date: Thu, 11 Dec 2014 08:19:02 -0600
50 Content-Type: multipart/mixed; boundary="_001_"
51 MIME-Version: 1.0
52
53 --_001_
54 Content-Type: text/plain
55
56 This is part 1.
57
58 --_001_
59 Content-Type: text/plain
60
61 This is part 2.
62
63 --_001_
64 Content-Type: text/enriched
65
66 This should not appear in the reply
67 because the content type isn't matched.
68
69 --_001_--
70 EOF
71
72 repl -noformat -convertarg text/plain '' -nowhatnowproc last
73 mhbuild "$actual"
74 check "$actual" "$expected"
75
76
77 # check that text is not quoted-printable encoded
78 # This tests the setting of reply_ct->c_reqencoding and
79 # (*text_plain_ct)->c_reqencoding in expand_pseudoheader().
80 start_test "don't encode text as quoted-printable"
81 cat >"$expected" <<'EOF'
82 From: recipient@example.com
83 To: sender@example.com
84 cc:
85 Fcc: +outbox
86 Subject: Re: test
87 Comments: In-reply-to sender@example.com
88 message dated "Thu, 11 Dec 2014 08:19:02 -0600."
89 MIME-Version: 1.0
90 Content-Type: text/plain; charset="US-ASCII"
91
92 sender@example.com writes:
93
94 > This is a very, very, very, very, very, very, very, very, very, very, very, long line.
95 EOF
96
97 cat >`mhpath new` <<'EOF'
98 From: sender@example.com
99 To: recipient@example.com
100 Subject: test
101 Date: Thu, 11 Dec 2014 08:19:02 -0600
102 Content-Type: multipart/mixed; boundary="_001_"
103 MIME-Version: 1.0
104
105 --_001_
106 Content-Type: text/plain
107
108 This is a very, very, very, very, very, very, very, very, very, very, very, long line.
109
110 --_001_--
111 EOF
112
113 #### Just prefix the text with "> ".
114 cp "${MH}" "${MH}.new"
115 cat >>"${MH}.new" <<EOF
116 mhbuild-convert-text: sed 's/^\(.\)/> \1/; s/^$/>/;' <%F
117 EOF
118 repl -filter mhl.replywithoutbody -convertarg text/plain '' \
119 -nowhatnowproc last
120 MH="${MH}.new" mhbuild "$actual"
121 rm "${MH}.new"
122 check "$actual" "$expected"
123
124
125 #### Make sure that this works with 8-bit encoding.
126 finish_test
127 require_locale en_US.UTF-8 en_US.UTF8 en_US.utf-8 en_US.utf8
128
129
130 # check -convertarg with multiple parts, 7 bit
131 start_test '-convertarg with multiple parts, 7 bit'
132 cat >"$expected" <<'EOF'
133 From: recipient@example.com
134 To: sender@example.com
135 cc:
136 Fcc: +outbox
137 Subject: Re: test
138 Comments: In-reply-to sender@example.com
139 message dated "Thu, 11 Dec 2014 08:19:02 -0600."
140 MIME-Version: 1.0
141 Content-Type: text/plain; charset="UTF-8"
142
143 sender@example.com writes:
144
145 > This is part 1.
146
147 > This is part 2.
148 EOF
149
150 cat >`mhpath new` <<'EOF'
151 From: sender@example.com
152 To: recipient@example.com
153 Subject: test
154 Date: Thu, 11 Dec 2014 08:19:02 -0600
155 Content-Type: multipart/mixed; boundary="_001_"
156 MIME-Version: 1.0
157
158 --_001_
159 Content-Type: text/plain
160
161 This is part 1.
162
163 --_001_
164 Content-Type: text/plain; charset="UTF-8"
165
166 This is part 2.
167
168 --_001_--
169 EOF
170
171 repl -filter mhl.replywithoutbody -convertarg text/plain '' -nowhatnowproc last
172 mhbuild "$actual"
173 check "$actual" "$expected"
174
175
176 # check -convertarg with multiple parts, 8 bit
177 start_test '-convertarg with multiple parts, 8 bit'
178 cat >"$expected" <<'EOF'
179 From: recipient@example.com
180 To: sender@example.com
181 cc:
182 Fcc: +outbox
183 Subject: Re: test
184 Comments: In-reply-to sender@example.com
185 message dated "Thu, 11 Dec 2014 08:19:02 -0600."
186 MIME-Version: 1.0
187 Content-Type: text/plain; charset="UTF-8"
188 Content-Transfer-Encoding: 8bit
189
190 sender@example.com writes:
191
192 > This is part 1.
193
194 > This is §2, with a non-ASCII character.
195 EOF
196
197 cat >`mhpath new` <<'EOF'
198 From: sender@example.com
199 To: recipient@example.com
200 Subject: test
201 Date: Thu, 11 Dec 2014 08:19:02 -0600
202 Content-Type: multipart/mixed; boundary="_001_"
203 MIME-Version: 1.0
204
205 --_001_
206 Content-Type: text/plain
207
208 This is part 1.
209
210 --_001_
211 Content-Type: text/plain; charset="UTF-8"
212
213 This is §2, with a non-ASCII character.
214
215 --_001_--
216 EOF
217
218 repl -filter mhl.replywithoutbody -convertarg text/plain '' -nowhatnowproc last
219 mhbuild "$actual"
220 check "$actual" "$expected"
221
222
223 # check message with text part in multipart/related
224 start_test 'check message with text part in multipart/related'
225 cat >"$expected" <<'EOF'
226 From: recipient@example.com
227 To: sender@example.com
228 cc:
229 Fcc: +outbox
230 Subject: Re: test with text part in multipart/related
231 Comments: In-reply-to sender@example.com
232 message dated "."
233 MIME-Version: 1.0
234 Content-Type: text/plain; charset="UTF-8"
235
236 sender@example.com writes:
237
238 > This is a test.
239 EOF
240
241 cat >`mhpath new` <<'EOF'
242 From: sender@example.com
243 To: recipient@example.com
244 Subject: test with text part in multipart/related
245 Content-Type: multipart/alternative; boundary="_001_"
246 MIME-Version: 1.0
247
248 --_001_
249 Content-Type: multipart/related; type="text/plain"; boundary="_002_"
250
251 --_002_
252 Content-Type: text/plain; charset="UTF-8"
253
254 This is a test.
255
256 --_002_--
257
258 --_001_--
259 EOF
260
261 repl -filter mhl.replywithoutbody -convertarg text/plain '' -nowhatnowproc last
262 mhbuild "$actual"
263 check "$actual" "$expected"
264
265
266 # check reply to calendar request
267 start_test 'check reply to calendar request'
268 cat >"$expected" <<'EOF'
269 From: recipient@example.com
270 To: sender@example.com
271 cc:
272 Fcc: +outbox
273 Subject: Re: test iCalendar reply
274 Comments: In-reply-to sender@example.com
275 message dated "."
276 MIME-Version: 1.0
277 Content-Type: text/calendar; method="REPLY"; charset="UTF-8"
278
279 BEGIN:VCALENDAR
280 METHOD:REPLY
281 PRODID:nmh mhical v0.1
282 VERSION:2.0
283 BEGIN:VTIMEZONE
284 TZID:Eastern Standard Time
285 BEGIN:STANDARD
286 DTSTART:16010101T020000
287 TZOFFSETFROM:-0400
288 TZOFFSETTO:-0500
289 RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
290 END:STANDARD
291 BEGIN:DAYLIGHT
292 DTSTART:16010101T020000
293 TZOFFSETFROM:-0500
294 TZOFFSETTO:-0400
295 RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
296 END:DAYLIGHT
297 END:VTIMEZONE
298 BEGIN:VEVENT
299 ORGANIZER;CN=Requester:MAILTO:requester@example.com
300 ATTENDEE;PARTSTAT=ACCEPTED;CN=Recip:MAILTO:recipient@example.com
301 SUMMARY;LANGUAGE=en-US:Accepted: test request
302 DTSTART;TZID=Eastern Standard Time:20150105T090000
303 DTEND;TZID=Eastern Standard Time:20150105T093000
304 UID:0123456789
305 CLASS:PUBLIC
306 PRIORITY:5
307 TRANSP:OPAQUE
308 STATUS:CONFIRMED
309 SEQUENCE:0
310 LOCATION;LANGUAGE=en-US:
311 END:VEVENT
312 END:VCALENDAR
313 EOF
314
315 cat >`mhpath new` <<'EOF'
316 From: sender@example.com
317 To: recipient@example.com
318 Subject: test iCalendar reply
319 Content-Type: text/calendar; charset="UTF-8"
320 MIME-Version: 1.0
321
322 BEGIN:VCALENDAR
323 METHOD:REQUEST
324 PRODID:test-convert
325 VERSION:2.0
326 BEGIN:VTIMEZONE
327 TZID:Eastern Standard Time
328 BEGIN:STANDARD
329 DTSTART:16010101T020000
330 TZOFFSETFROM:-0400
331 TZOFFSETTO:-0500
332 RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
333 END:STANDARD
334 BEGIN:DAYLIGHT
335 DTSTART:16010101T020000
336 TZOFFSETFROM:-0500
337 TZOFFSETTO:-0400
338 RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
339 END:DAYLIGHT
340 END:VTIMEZONE
341 BEGIN:VEVENT
342 ORGANIZER;CN=Requester:MAILTO:requester@example.com
343 ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Requestee1
344 :MAILTO:requestee1@example.com
345 ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Requestee2
346 :MAILTO:requestee2@example.com
347 ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=Requestee3
348 :MAILTO:requestee3@example.com
349 SUMMARY;LANGUAGE=en-US:test request
350 DTSTART;TZID=Eastern Standard Time:20150105T090000
351 DTEND;TZID=Eastern Standard Time:20150105T093000
352 UID:0123456789
353 CLASS:PUBLIC
354 PRIORITY:5
355 DTSTAMP:20150101T171600Z
356 TRANSP:OPAQUE
357 STATUS:CONFIRMED
358 SEQUENCE:0
359 LOCATION;LANGUAGE=en-US:
360 BEGIN:VALARM
361 ACTION:DISPLAY
362 DESCRIPTION:REMINDER
363 TRIGGER;RELATED=START:-PT15M
364 END:VALARM
365 END:VEVENT
366 END:VCALENDAR
367 EOF
368
369 actual="$MH_TEST_DIR/test-convert$$.actual"
370 repl -noformat \
371 -convertargs text/calendar '-reply accept -contenttype' -nowhatnowproc last
372 SIGNATURE=Recip mhbuild - <`mhpath +`/draft | egrep -v '^DTSTAMP:' >"$actual"
373 check "$actual" "$expected"
374
375
376 finish_test
377 exit $failed