File: test-dist

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (514 lines) | stat: -rwxr-xr-x 12,825 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#!/bin/sh
######################################################
#
# Test dist
#
######################################################

set -e

if test -z "${MH_OBJ_DIR}"; then
    srcdir=`dirname $0`/../..
    MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi

. "$MH_OBJ_DIR/test/common.sh"

setup_test

check_exit '-eq 1' dist -
check_exit '-eq 1' dist -editor
check_exit '-eq 1' dist -editor foo -editor
check_exit '-eq 1' dist -nowhatnowproc -whatnowproc foo -whatnowproc
check_exit '-eq 1' dist -file
check_exit '-eq 1' dist -file foo -file bar
check_exit '-eq 1' dist -form
check_exit '-eq 1' dist -draftfolder
check_exit '-eq 1' dist -draftfolder foo -draftfolder bar
check_exit '-eq 1' dist -draftmessage
check_exit '-eq 1' dist -draftmessage 42 -draftmessage 314
check_exit '-eq 1' dist -from
check_exit '-eq 1' dist -to
check_exit '-eq 1' dist -cc
check_exit '-eq 1' dist -fcc
check_exit '-eq 1' dist -width
check_exit '-eq 1' dist -width 42 -width 0
check_exit '-eq 1' dist -atfile -noatfile -
check_exit '-eq 1' dist + @
check_exit '-eq 1' dist 42 314
check_exit '-eq 1' dist -file foo 42

expected=$MH_TEST_DIR/$$.expected
expected_err=$MH_TEST_DIR/$$.expected_err
actual=$MH_TEST_DIR/$$.actual
actual_err=$MH_TEST_DIR/$$.actual_err
localmbox=`${MH_LIBEXEC_DIR}/ap -format "%(localmbox)" 0 | sed 's/^<\(.*\)>$/\1/'`

#### Use sendmail/pipe below to override default mts.
mts_fakesendmail="${MHMTSCONF}-fakesendmail"
sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
MHMTSCONF="$mts_fakesendmail"

# arguments: dist switches
test_dist ()
{
  printf 'send\n' | run_prog dist "$@" >/dev/null

  # fakesendmail drops the message and any cc's into this mbox.
  mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
  inc -silent -file "$mbox"
  rm -f "$mbox"

  # It's hard to calculate the exact Date: header post is going to
  # use, so we'll just use sed to remove the actual date so we can
  # easily compare it against our "correct" output.
  sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"

  check "$expected" "$actual"
}

# arguments: message_number
wait_for_annotation ()
{
  # The annotation is done by a separate process, so we need to wait for
  # it to complete.
  i=1
  until grep '^Resent:' "${MH_TEST_DIR}"/Mail/inbox/$1 >/dev/null; do
    sleep 1
    arith_eval $i + 1
    i=$arith_val
    if [ $i -gt 60 ]; then
      printf '%s: -annotate failed, will not wait any longer\n' "$0"
      break
    fi
  done
}


# check -help
start_test "-help"
cat >"$expected" <<EOF
Usage: dist [+folder] [msg] [switches]
  switches are:
  -[no]annotate
  -draftfolder +folder
  -draftmessage msg
  -nodraftfolder
  -editor editor
  -noedit
  -form formfile
  -[no]inplace
  -whatnowproc program
  -nowhatnowproc
  -version
  -help
  -from address
  -to address
  -cc address
  -fcc mailbox
  -width columns
  -[no]atfile
EOF

#### Skip nmh intro text.
dist -help 2>&1 | sed '/^$/,$d' >"$actual"
check "$expected" "$actual"

# check -version
start_test "-version"
case `dist -v` in
  dist\ --*) ;;
  *        ) printf '%s: dist -v generated unexpected output\n' "$0" >&2
             failed=`expr ${failed:-0} + 1`;;
esac

# check unknown switch
start_test "unknown switch"
run_test "dist -nonexistent" 'dist: -nonexistent unknown'

folder +outbox -create -fast >/dev/null
folder +inbox -fast 1 >/dev/null

# For most tests, use -nowhatnow and just check that the draft
# looks correct.

# check basic dist operation, including -noedit and -to
start_test "basic dist operation, including -noedit and -to"
cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 1
EOF

test_dist -noedit -to somebody@example.com

# check +folder and msg
start_test "+folder and msg"
folder +outbox -fast >/dev/null

cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 1
EOF

test_dist +inbox 1 -noedit -to somebody@example.com

# check -form
start_test "-form"
cat >"${MH_TEST_DIR}/Mail/distform" <<'EOF'
Resent-From: me@example.com
Resent-To: you@example.com
EOF

cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: me@example.com
Resent-To: you@example.com
Resent-Date:

This is message number 1
EOF

test_dist 1 -noedit -form "${MH_TEST_DIR}"/Mail/distform

rm "${MH_TEST_DIR}"/Mail/distform

# check -annotate
start_test "-annotate"
cat >"$expected" <<EOF
From: Test2 <test2@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 2@test.nmh
Subject: Testing message 2
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 2
EOF

test_dist 2 -noedit -to somebody@example.com -annotate
wait_for_annotation 2

cat >"$expected" <<EOF
Resent:
Resent: somebody@example.com
From: Test2 <test2@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 2@test.nmh
Subject: Testing message 2

This is message number 2
EOF

# Strip date from line of this form:
# Resent: Sat, 06 Oct 2012 08:24:08 -0500
sed -e 's/^Resent:.*:.*/Resent:/' "${MH_TEST_DIR}"/Mail/inbox/2 >"$actual"

check "$expected" "$actual"

# check -noannotate
start_test "-noannotate"
cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 1
EOF

test_dist 1 -noedit -to somebody@example.com -annotate -noannotate

cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1

This is message number 1
EOF

check "${MH_TEST_DIR}"/Mail/inbox/1 "$expected" 'keep first'

check_for_hard_links
if [ $hard_links_supported -eq 1 ]; then
  # check -noinplace
  start_test "-noinplace"
  # Hard link the message and verify that the new one doesn't get annotated.
  cp "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.copy"
  ln "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link"
  cat >"$expected" <<EOF
From: Test8 <test8@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 8@test.nmh
Subject: Testing message 8
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 8
EOF
  test_dist 8 -noedit -to somebody@example.com -annotate -noinplace
  wait_for_annotation 8
  mv -f "${MH_TEST_DIR}/Mail/inbox/8.copy" "${MH_TEST_DIR}/Mail/inbox/8"
  check "${MH_TEST_DIR}/Mail/inbox/8" "${MH_TEST_DIR}/Mail/inbox/8.link" \
    'keep first'

  # check -inplace
  start_test "-inplace"
  # Hard link the message and verify that the new one does get annotated.
  ln "${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
  cat >"$expected" <<EOF
From: Test9 <test9@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 9@test.nmh
Subject: Testing message 9
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 9
EOF
  test_dist 9 -noedit -to somebody@example.com -annotate -noinplace -inplace
  wait_for_annotation 9
  check "${MH_TEST_DIR}/Mail/inbox/9" "${MH_TEST_DIR}/Mail/inbox/9.link"
fi

# check -draftfolder
start_test "-draftfolder"
cat >"$expected" <<EOF
From: Test3 <test3@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 3@test.nmh
Subject: Testing message 3
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 3
EOF

test_dist 3 -noedit -to somebody@example.com -draftfolder drafts

# check -draftmsg
start_test "-draftmsg"
cat >"$expected" <<EOF
From: Test3 <test3@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 3@test.nmh
Subject: Testing message 3
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 3
EOF

touch $MH_TEST_DIR/Mail/drafts/3
test_dist 3 -noedit -to somebody@example.com -draftfolder drafts -draftmessage 2

# check -nodraftfolder
start_test "-nodraftfolder"
cat >"$expected" <<EOF
From: Test3 <test3@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 3@test.nmh
Subject: Testing message 3
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 3
EOF

test_dist 3 -noedit -to somebody@example.com -draftfolder nonexistent \
  -nodraftfolder
if test -d "${MH_TEST_DIR}/Mail/nonexistent"; then
  echo "$0: -nodraftfolder test failed."
  failed=`expr ${failed:-0} + 1`
fi

# check -from
start_test "-from"
cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: me@example.com
Resent-To: somebody@example.com
Resent-Date:

This is message number 1
EOF

test_dist 1 -noedit -to somebody@example.com -from me@example.com

# check -cc
start_test "-cc"
cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-cc: cc@example.com
Resent-Date:

This is message number 1
EOF

test_dist 1 -noedit -to somebody@example.com -cc cc@example.com

# check -fcc
start_test "-fcc"
cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 1
EOF

test_dist 1 -noedit -to somebody@example.com -fcc outbox
run_test 'scan +outbox -width 6' '   1  '

# check -fcc with +
start_test "-fcc with +"
cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: ${localmbox}
Resent-To: somebody@example.com
Resent-Date:

This is message number 1
EOF

test_dist +inbox 1 -noedit -to somebody@example.com -fcc +outbox
run_test 'scan +outbox -width 6 2' '   2  '

# check Distribute- and Distribution-
start_test "Distribute- and Distribution-"
cat >"$expected" <<EOF
  -- Network Recipients --
  dist-recipient at example.com
EOF

folder -f +inbox >/dev/null
arith_eval `pick last` + 1
new_msg=$arith_val
cat >`mhpath new` <<EOF
From: Test$new_msg <test$new_msg@example.com>
Date: Sun, 10 May 2020 10:00:00
EOF

cat >`mhpath new` <<EOF
Distribution-From: <a@example.com>
Distribute-To: <dist-recipient@example.com>
EOF

mhdist=`pick last` mhaltmsg=`mhpath $new_msg` whom `mhpath last` >"$actual"
check "$expected" "$actual"

#
# Check that dist encodes headers using RFC-2047 properly
#
start_test "dist encodes headers using RFC-2047 properly"
require_locale $en_locales

cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: =?UTF-8?Q?Mr_F=C3=B8o_Bar?= <resent-from@example.com>
Resent-To: =?UTF-8?Q?Mr_Nobod=C3=BF?= <resent-to@example.com>
Resent-Date:

This is message number 1
EOF

test_dist +inbox 1 -noedit -from 'Mr Føo Bar <resent-from@example.com>' \
	  -to 'Mr Nobodÿ <resent-to@example.com>' -fcc +outbox

# check that mhdraft is assembled properly
start_test "check mhdraft assembly"

cat >"$expected" <<EOF
From: Test1 <test1@example.com>
To: Some User <user@example.com>
Date: Fri, 29 Sep 2006 00:00:00
Message-Id: 1@test.nmh
Subject: Testing message 1
Resent-From: resender@example.com
Resent-To: recipient@example.com
Resent-cc:
Resent-fcc:

This is message number 1
EOF

#### Capture $mhdraft in a postproc.  Then check to see that it doesn't
#### have, for example, extra spaces in the header fields.
postproc="${MH_TEST_DIR}/Mail/postproc"
cat >"$postproc" <<EOF
cp \$mhdraft $actual
EOF
chmod +x "$postproc"
sed -e "s%\(postproc:\).*%\1 $postproc%" "$MH" >"$MH.new"
mv -f "$MH.new" "$MH"

printf 'send\n' | run_prog dist +inbox 1 -noedit -from 'resender@example.com' \
    -to 'recipient@example.com' >/dev/null

check "$actual" "$expected"


finish_test
exit ${failed:-0}