cc-test.sh: do a simple \`Resend' test
[s-mailx.git] / cc-test.sh
blob4bf310252a0e11a87a829f97b8aed3d426b2e946
1 #!/bin/sh -
2 #@ Usage: ./cc-test.sh [--check-only [s-nail-binary]]
4 SNAIL=./s-nail
5 ARGS='-n# -Sstealthmua -Snosave -Sexpandaddr=restrict -Sdotlock-ignore-error'
6 CONF=./make.rc
7 BODY=./.cc-body.txt
8 MBOX=./.cc-test.mbox
10 MAKE="${MAKE:-`command -v make`}"
11 awk=${awk:-`command -v awk`}
12 cat=${cat:-`command -v cat`}
13 cksum=${cksum:-`command -v cksum`}
14 rm=${rm:-`command -v rm`}
15 sed=${sed:-`command -v sed`}
16 grep=${grep:-`command -v grep`}
18 ## -- >8 -- 8< -- ##
20 export SNAIL ARGS CONF BODY MBOX MAKE awk cat cksum rm sed grep
22 # NOTE! UnixWare 7.1.4 gives ISO-10646-Minimum-European-Subset for
23 # nl_langinfo(CODESET), then, so also overwrite ttycharset.
24 # (In addition this setup allows us to succeed on TinyCore 4.4 that has no
25 # other locales than C/POSIX installed by default!)
26 LC=en_US.UTF-8
27 LC_ALL=${LC} LANG=${LC}
28 ttycharset=UTF-8
29 export LC_ALL LANG ttycharset
31 ESTAT=0
33 usage() {
34 echo >&2 "Usage: ./cc-test.sh [--check-only [s-nail-binary]]"
35 exit 1
38 CHECK_ONLY=
39 [ ${#} -gt 0 ] && {
40 [ "${1}" = --check-only ] || usage
41 [ ${#} -gt 2 ] && usage
42 [ ${#} -eq 2 ] && SNAIL="${2}"
43 [ -x "${SNAIL}" ] || usage
44 CHECK_ONLY=1
47 # cc_all_configs()
48 # Test all configs TODO doesn't cover all *combinations*, stupid!
49 cc_all_configs() {
50 < ${CONF} ${awk} '
51 BEGIN {i = 0}
52 /^[[:space:]]*WANT_/ {
53 sub(/^[[:space:]]*/, "")
54 # This bails for UnixWare 7.1.4 awk(1), but preceeding = with \
55 # does not seem to be a compliant escape for =
56 #sub(/=.*$/, "")
57 $1 = substr($1, 1, index($1, "=") - 1)
58 if ($1 == "WANT_AUTOCC")
59 next
60 data[i++] = $1
62 END {
63 for (j = 1; j < i; ++j) {
64 for (k = 1; k < j; ++k)
65 printf data[k] "=1 "
66 for (k = j; k < i; ++k)
67 printf data[k] "=0 "
68 printf "WANT_AUTOCC=1\n"
70 for (k = 1; k < j; ++k)
71 printf data[k] "=0 "
72 for (k = j; k < i; ++k)
73 printf data[k] "=1 "
74 printf "WANT_AUTOCC=1\n"
77 printf "CONFIG=NULL WANT_AUTOCC=0\n"
78 printf "CONFIG=NULL WANT_AUTOCC=1\n"
79 printf "CONFIG=NULLI WANT_AUTOCC=0\n"
80 printf "CONFIG=NULLI WANT_AUTOCC=1\n"
81 printf "CONFIG=MINIMAL WANT_AUTOCC=0\n"
82 printf "CONFIG=MINIMAL WANT_AUTOCC=1\n"
83 printf "CONFIG=MEDIUM WANT_AUTOCC=0\n"
84 printf "CONFIG=MEDIUM WANT_AUTOCC=1\n"
85 printf "CONFIG=NETSEND WANT_AUTOCC=0\n"
86 printf "CONFIG=NETSEND WANT_AUTOCC=1\n"
87 printf "CONFIG=MAXIMAL WANT_AUTOCC=0\n"
88 printf "CONFIG=MAXIMAL WANT_AUTOCC=1\n"
89 printf "CONFIG=DEVEL WANT_AUTOCC=0\n"
90 printf "CONFIG=DEVEL WANT_AUTOCC=1\n"
91 printf "CONFIG=ODEVEL WANT_AUTOCC=0\n"
92 printf "CONFIG=ODEVEL WANT_AUTOCC=1\n"
94 ' | while read c; do
95 printf "\n\n##########\n$c\n"
96 printf "\n\n##########\n$c\n" >&2
97 sh -c "${MAKE} ${c}"
98 t_all
99 ${MAKE} distclean
100 done
103 # cksum_test()
104 # Read mailbox $2, strip non-constant headers and MIME boundaries, query the
105 # cksum(1) of the resulting data and compare against the checksum $3
106 cksum_test() {
107 tid=${1} f=${2} s=${3}
108 printf "${tid}: "
109 csum="`${sed} -e '/^From /d' -e '/^Date: /d' \
110 -e '/^ boundary=/d' -e '/^--=-=/d' < \"${f}\" \
111 -e '/^\[-- Message/d' | ${cksum}`";
112 if [ "${csum}" = "${s}" ]; then
113 printf 'ok\n'
114 else
115 ESTAT=1
116 printf 'error: checksum mismatch (got %s)\n' "${csum}"
120 have_feat() {
122 echo 'feat' |
123 MAILRC=/dev/null "${SNAIL}" ${ARGS} |
124 ${grep} ${1}
125 ) >/dev/null 2>&1
128 # t_behave()
129 # Basic (easily testable) behaviour tests
130 t_behave() {
131 # Test for [d1f1a19]
132 ${rm} -f "${MBOX}"
133 printf 'echo +nix\nset folder=/\necho +nix\nset nofolder\necho +nix\nx' |
134 MAILRC=/dev/null "${SNAIL}" ${ARGS} > "${MBOX}"
135 cksum_test behave:001 "${MBOX}" '4214021069 15'
137 # POSIX: setting *noprompt*/prompt='' shall prevent prompting TODO
138 # TODO for this to be testable we need a way to echo a variable
139 # TODO or to force echo of the prompt
141 __behave_ifelse
143 # FIXME __behave_alias
145 # FIXME __behave_mlist
147 have_feat SSL/TLS && have_feat S/MIME && __behave_smime
150 __behave_ifelse() {
151 # Nestable conditions test
152 ${rm} -f "${MBOX}"
153 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" ${ARGS} > "${MBOX}"
154 if 0
155 echo 1.err
156 else
157 echo 1.ok
158 endif
159 if 1
160 echo 2.ok
161 else
162 echo 2.err
163 endif
164 if $dietcurd
165 echo 3.err
166 else
167 echo 3.ok
168 endif
169 set dietcurd=yoho
170 if $dietcurd
171 echo 4.ok
172 else
173 echo 4.err
174 endif
175 if $dietcurd == 'yoho'
176 echo 5.ok
177 else
178 echo 5.err
179 endif
180 if $dietcurd != 'yoho'
181 echo 6.err
182 else
183 echo 6.ok
184 endif
185 # Nesting
186 if faLse
187 echo 7.err1
188 if tRue
189 echo 7.err2
190 if yEs
191 echo 7.err3
192 else
193 echo 7.err4
194 endif
195 echo 7.err5
196 endif
197 echo 7.err6
198 else
199 echo 7.ok7
200 if YeS
201 echo 7.ok8
202 if No
203 echo 7.err9
204 else
205 echo 7.ok9
206 endif
207 echo 7.ok10
208 else
209 echo 7.err11
210 if yeS
211 echo 7.err12
212 else
213 echo 7.err13
214 endif
215 endif
216 echo 7.ok14
217 endif
218 if r
219 echo 8.ok1
220 if R
221 echo 8.ok2
222 else
223 echo 8.err2
224 endif
225 echo 8.ok3
226 else
227 echo 8.err1
228 endif
229 if s
230 echo 9.err1
231 else
232 echo 9.ok1
233 if S
234 echo 9.err2
235 else
236 echo 9.ok2
237 endif
238 echo 9.ok3
239 endif
240 # `elif'
241 if $dietcurd == 'yohu'
242 echo 10.err1
243 elif $dietcurd == 'yoha'
244 echo 10.err2
245 elif $dietcurd == 'yohe'
246 echo 10.err3
247 elif $dietcurd == 'yoho'
248 echo 10.ok1
249 if $dietcurd == 'yohu'
250 echo 10.err4
251 elif $dietcurd == 'yoha'
252 echo 10.err5
253 elif $dietcurd == 'yohe'
254 echo 10.err6
255 elif $dietcurd == 'yoho'
256 echo 10.ok2
257 if $dietcurd == 'yohu'
258 echo 10.err7
259 elif $dietcurd == 'yoha'
260 echo 10.err8
261 elif $dietcurd == 'yohe'
262 echo 10.err9
263 elif $dietcurd == 'yoho'
264 echo 10.ok3
265 else
266 echo 10.err10
267 endif
268 else
269 echo 10.err11
270 endif
271 else
272 echo 10.err12
273 endif
274 # integer conversion, <..>..
275 set dietcurd=10
276 if $dietcurd < 11
277 echo 11.ok1
278 if $dietcurd > 9
279 echo 11.ok2
280 else
281 echo 11.err2
282 endif
283 if $dietcurd == 10
284 echo 11.ok3
285 else
286 echo 11.err3
287 endif
288 if $dietcurd >= 10
289 echo 11.ok4
290 else
291 echo 11.err4
292 endif
293 if $dietcurd <= 10
294 echo 11.ok5
295 else
296 echo 11.err5
297 endif
298 if $dietcurd >= 11
299 echo 11.err6
300 else
301 echo 11.ok6
302 endif
303 if $dietcurd <= 9
304 echo 11.err7
305 else
306 echo 11.ok7
307 endif
308 else
309 echo 11.err1
310 endif
311 set dietcurd=Abc
312 if $dietcurd < aBd
313 echo 12.ok1
314 if $dietcurd > abB
315 echo 12.ok2
316 else
317 echo 12.err2
318 endif
319 if $dietcurd == aBC
320 echo 12.ok3
321 else
322 echo 12.err3
323 endif
324 if $dietcurd >= AbC
325 echo 12.ok4
326 else
327 echo 12.err4
328 endif
329 if $dietcurd <= ABc
330 echo 12.ok5
331 else
332 echo 12.err5
333 endif
334 if $dietcurd >= abd
335 echo 12.err6
336 else
337 echo 12.ok6
338 endif
339 if $dietcurd <= abb
340 echo 12.err7
341 else
342 echo 12.ok7
343 endif
344 else
345 echo 12.err1
346 endif
347 if $dietcurd =@ aB
348 echo 13.ok
349 else
350 echo 13.err
351 endif
352 if $dietcurd =@ bC
353 echo 14.ok
354 else
355 echo 14.err
356 endif
357 if $dietcurd !@ aB
358 echo 15.err
359 else
360 echo 15.ok
361 endif
362 if $dietcurd !@ bC
363 echo 15.err
364 else
365 echo 15.ok
366 endif
367 if $dietcurd =@ Cd
368 echo 16.err
369 else
370 echo 16.ok
371 endif
372 if $dietcurd !@ Cd
373 echo 17.ok
374 else
375 echo 17.err
376 endif
377 set diet=abc curd=abc
378 if $diet == $curd
379 echo 18.ok
380 else
381 echo 18.err
382 endif
383 set diet=abc curd=abcd
384 if $diet != $curd
385 echo 19.ok
386 else
387 echo 19.err
388 endif
389 # 1. Shitty grouping capabilities as of today
390 unset diet curd ndefined
391 if [ [ false ] || [ false ] || [ true ] ] && [ [ false ] || [ true ] ] && \
392 [ yes ]
393 echo 20.ok
394 else
395 echo 20.err
396 endif
397 if [ [ [ [ 0 ] || [ 1 ] ] && [ [ 1 ] || [ 0 ] ] ] && [ 1 ] ] && [ yes ]
398 echo 21.ok
399 else
400 echo 21.err
401 endif
402 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] ]
403 echo 22.ok
404 else
405 echo 22.err
406 endif
407 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] || [ [ 1 ] ] ]
408 echo 23.ok
409 else
410 echo 23.err
411 endif
412 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] || [ [ 1 ] ] || [ 1 ] ] && [ no ]
413 echo 24.err
414 else
415 echo 24.ok
416 endif
417 if [ [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] || [ [ 1 ] ] || [ 1 ] ] \
418 && [ no ] || [ yes ]
419 echo 25.ok
420 else
421 echo 25.err
422 endif
423 if [ [ [ [ [ [ [ 1 ] ] && [ 1 ] ] && [ 1 ] ] && [ 1 ] ] ] && [ 1 ] ]
424 echo 26.ok
425 else
426 echo 26.err
427 endif
428 if [ [ [ [ [ [ [ 1 ] ] && [ 1 ] ] && [ 1 ] ] && [ 1 ] ] ] && [ 0 ] ]
429 echo 27.err
430 else
431 echo 27.ok
432 endif
433 if [ [ [ [ [ [ [ 1 ] ] && [ 1 ] ] && [ 0 ] ] && [ 1 ] ] ] && [ 1 ] ]
434 echo 28.err
435 else
436 echo 28.ok
437 endif
438 if [ [ [ [ [ [ [ 0 ] ] && [ 1 ] ] && [ 1 ] ] && [ 1 ] ] ] && [ 1 ] ]
439 echo 29.err
440 else
441 echo 29.ok
442 endif
443 if [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] && [ 0 ]
444 echo 30.err
445 else
446 echo 30.ok
447 endif
448 if [ 1 ] || [ 0 ] || [ 0 ] || [ 0 ] && [ 1 ]
449 echo 31.ok
450 else
451 echo 31.err
452 endif
453 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 0 ]
454 echo 32.err
455 else
456 echo 32.ok
457 endif
458 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 1 ]
459 echo 33.ok
460 else
461 echo 33.err
462 endif
463 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 0 ] || [ 1 ] && [ 0 ]
464 echo 34.err
465 else
466 echo 34.ok
467 endif
468 if [ 0 ] || [ 0 ] || [ 0 ] || [ 1 ] && [ 0 ] || [ 1 ] && [ 1 ]
469 echo 35.ok
470 else
471 echo 35.err
472 endif
473 set diet=yo curd=ho
474 if [ [ $diet == 'yo' ] && [ $curd == 'ho' ] ] && [ $ndefined ]
475 echo 36.err
476 else
477 echo 36.ok
478 endif
479 set ndefined
480 if [ [ $diet == 'yo' ] && [ $curd == 'ho' ] ] && [ $ndefined ]
481 echo 37.ok
482 else
483 echo 37.err
484 endif
485 # 2. Shitty grouping capabilities as of today
486 unset diet curd ndefined
487 if [ false || false || true ] && [ false || true ] && yes
488 echo 40.ok
489 else
490 echo 40.err
491 endif
492 if [ [ [ 0 || 1 ] && [ 1 || 0 ] ] && 1 ] && [ yes ]
493 echo 41.ok
494 else
495 echo 41.err
496 endif
497 if [ 1 || 0 || 0 || 0 ]
498 echo 42.ok
499 else
500 echo 42.err
501 endif
502 if [ 1 || 0 || 0 || 0 || [ 1 ] ]
503 echo 43.ok
504 else
505 echo 43.err
506 endif
507 if [ 1 || 0 || 0 || 0 || [ 1 ] || 1 ] && no
508 echo 44.err
509 else
510 echo 44.ok
511 endif
512 if [ 1 || 0 || 0 || 0 || 1 || [ 1 ] ] && no || [ yes ]
513 echo 45.ok
514 else
515 echo 45.err
516 endif
517 if [ [ [ [ [ [ 1 ] && 1 ] && 1 ] && 1 ] ] && [ 1 ] ]
518 echo 46.ok
519 else
520 echo 46.err
521 endif
522 if [ [ [ [ [ [ 1 ] && 1 ] && 1 ] && [ 1 ] ] ] && 0 ]
523 echo 47.err
524 else
525 echo 47.ok
526 endif
527 if [ [ [ [ [ [ [ 1 ] ] && 1 ] && 0 ] && [ 1 ] ] ] && 1 ]
528 echo 48.err
529 else
530 echo 48.ok
531 endif
532 if [ [ [ [ [ [ 0 ] && 1 ] && 1 ] && 1 ] ] && 1 ]
533 echo 49.err
534 else
535 echo 49.ok
536 endif
537 if 1 || 0 || 0 || 0 && 0
538 echo 50.err
539 else
540 echo 50.ok
541 endif
542 if 1 || 0 || 0 || 0 && 1
543 echo 51.ok
544 else
545 echo 51.err
546 endif
547 if 0 || 0 || 0 || 1 && 0
548 echo 52.err
549 else
550 echo 52.ok
551 endif
552 if 0 || 0 || 0 || 1 && 1
553 echo 53.ok
554 else
555 echo 53.err
556 endif
557 if 0 || 0 || 0 || 1 && 0 || 1 && 0
558 echo 54.err
559 else
560 echo 54.ok
561 endif
562 if 0 || 0 || 0 || 1 && 0 || 1 && 1
563 echo 55.ok
564 else
565 echo 55.err
566 endif
567 set diet=yo curd=ho
568 if [ $diet == 'yo' && $curd == 'ho' ] && $ndefined
569 echo 56.err
570 else
571 echo 56.ok
572 endif
573 if $diet == 'yo' && $curd == 'ho' && $ndefined
574 echo 57.err
575 else
576 echo 57.ok
577 endif
578 set ndefined
579 if [ $diet == 'yo' && $curd == 'ho' ] && $ndefined
580 echo 57.ok
581 else
582 echo 57.err
583 endif
584 if $diet == 'yo' && $curd == 'ho' && $ndefined
585 echo 58.ok
586 else
587 echo 58.err
588 endif
589 if [ [ [ [ [ [ $diet == 'yo' && $curd == 'ho' && $ndefined ] ] ] ] ] ]
590 echo 59.ok
591 else
592 echo 59.err
593 endif
594 # Unary !
595 if ! 0 && ! ! 1 && ! ! ! ! 2 && 3
596 echo 80.ok
597 else
598 echo 80.err
599 endif
600 if ! 0 && ! [ ! 1 ] && ! [ ! [ ! [ ! 2 ] ] ] && 3
601 echo 81.ok
602 else
603 echo 81.err
604 endif
605 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && 3
606 echo 82.ok
607 else
608 echo 82.err
609 endif
610 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && ! 3
611 echo 83.err
612 else
613 echo 83.ok
614 endif
615 if [ ! 0 ] && [ ! [ ! 1 ] ] && ! [ [ ! [ ! [ ! [ 2 ] ] ] ] ] && ! 3
616 echo 84.err
617 else
618 echo 84.ok
619 endif
620 if [ ! 0 ] && ! [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && 3
621 echo 85.err
622 else
623 echo 85.ok
624 endif
625 if ! [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] && 3
626 echo 86.err
627 else
628 echo 86.ok
629 endif
630 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ 2 ] ] ] ] ] || 3
631 echo 87.ok
632 else
633 echo 87.err
634 endif
635 if [ ! 0 ] && [ ! ! [ ! ! 1 ] ] && [ ! ! [ ! ! [ ! ! [ ! ! [ 2 ] ] ] ] ]
636 echo 88.ok
637 else
638 echo 88.err
639 endif
640 # Unary !, odd
641 if ! 0 && ! ! 1 && ! ! ! 0 && 3
642 echo 90.ok
643 else
644 echo 90.err
645 endif
646 if ! 0 && ! [ ! 1 ] && ! [ ! [ ! [ 0 ] ] ] && 3
647 echo 91.ok
648 else
649 echo 91.err
650 endif
651 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ [ 0 ] ] ] ] ] && 3
652 echo 92.ok
653 else
654 echo 92.err
655 endif
656 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! ! [ ! [ ! 0 ] ] ] ] && ! 3
657 echo 93.err
658 else
659 echo 93.ok
660 endif
661 if [ ! 0 ] && [ ! [ ! 1 ] ] && ! [ ! [ ! [ ! [ ! 0 ] ] ] ] && 3
662 echo 94.ok
663 else
664 echo 94.err
665 endif
666 if [ ! 0 ] && ! [ ! [ ! 1 ] ] && [ ! ! [ ! [ ! [ ! [ 0 ] ] ] ] ] && 3
667 echo 95.err
668 else
669 echo 95.ok
670 endif
671 if ! [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! ! 0 ] ] ] ] && 3
672 echo 96.err
673 else
674 echo 96.ok
675 endif
676 if [ ! 0 ] && [ ! [ ! 1 ] ] && [ ! [ ! [ ! [ ! [ ! 0 ] ] ] ] ] || 3
677 echo 97.ok
678 else
679 echo 97.err
680 endif
681 if [ ! 0 ] && [ ! ! [ ! ! 1 ] ] && [ ! ! [ ! ! [ ! ! [ ! [ 0 ] ] ] ] ]
682 echo 98.ok
683 else
684 echo 98.err
685 endif
686 __EOT
687 cksum_test behave:if-normal "${MBOX}" '3542193361 607'
689 if have_feat REGEX; then
690 ${rm} -f "${MBOX}"
691 ${cat} <<- '__EOT' | MAILRC=/dev/null "${SNAIL}" ${ARGS} > "${MBOX}"
692 set dietcurd=yoho
693 if $dietcurd =~ '^yo.*'
694 echo 1.ok
695 else
696 echo 1.err
697 endif
698 if $dietcurd =~ '^yoho.+'
699 echo 2.err
700 else
701 echo 2.ok
702 endif
703 if $dietcurd !~ '.*ho$'
704 echo 3.err
705 else
706 echo 3.ok
707 endif
708 if $dietcurd !~ '.+yoho$'
709 echo 4.ok
710 else
711 echo 4.err
712 endif
713 if [ $dietcurd !~ '.+yoho$' ]
714 echo 5.ok
715 else
716 echo 5.err
717 endif
718 if ! [ $dietcurd =~ '.+yoho$' ]
719 echo 6.ok
720 else
721 echo 6.err
722 endif
723 if ! ! [ $dietcurd !~ '.+yoho$' ]
724 echo 7.ok
725 else
726 echo 7.err
727 endif
728 if ! [ ! [ $dietcurd !~ '.+yoho$' ] ]
729 echo 8.ok
730 else
731 echo 8.err
732 endif
733 if [ ! [ ! [ $dietcurd !~ '.+yoho$' ] ] ]
734 echo 9.ok
735 else
736 echo 9.err
737 endif
738 if ! [ ! [ ! [ $dietcurd !~ '.+yoho$' ] ] ]
739 echo 10.err
740 else
741 echo 10.ok
742 endif
743 if ! ! ! $dietcurd !~ '.+yoho$'
744 echo 11.err
745 else
746 echo 11.ok
747 endif
748 if ! ! ! $dietcurd =~ '.+yoho$'
749 echo 12.ok
750 else
751 echo 12.err
752 endif
753 if ! [ ! ! [ ! [ $dietcurd !~ '.+yoho$' ] ] ]
754 echo 13.ok
755 else
756 echo 13.err
757 endif
758 set diet=abc curd='^abc$'
759 if $diet =~ $curd
760 echo 14.ok
761 else
762 echo 14.err
763 endif
764 set diet=abc curd='^abcd$'
765 if $diet !~ $curd
766 echo 15.ok
767 else
768 echo 15.err
769 endif
770 __EOT
771 cksum_test behave:if-regex "${MBOX}" '439960016 81'
775 __behave_smime() { # FIXME add test/ dir, unroll tests therein, regular enable!
776 printf 'behave:s/mime: .. generating test key and certificate ..\n'
777 ${cat} <<-_EOT > ./t.conf
778 [ req ]
779 default_bits = 1024
780 default_keyfile = keyfile.pem
781 distinguished_name = req_distinguished_name
782 attributes = req_attributes
783 prompt = no
784 output_password =
786 [ req_distinguished_name ]
787 C = GB
788 ST = Over the
789 L = rainbow
790 O = S-nail
791 OU = S-nail.smime
792 CN = S-nail.test
793 emailAddress = test@localhost
795 [ req_attributes ]
796 challengePassword =
797 _EOT
798 openssl req -x509 -nodes -days 3650 -config ./t.conf \
799 -newkey rsa:1024 -keyout ./tkey.pem -out ./tcert.pem >/dev/null 2>&1
800 ${rm} -f ./t.conf
801 ${cat} ./tkey.pem ./tcert.pem > ./tpair.pem
803 printf "behave:s/mime:sign/verify: "
804 echo bla |
805 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
806 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
807 -Ssmime-sign -Sfrom=test@localhost \
808 -s 'S/MIME test' ./VERIFY
809 # TODO CHECK
810 printf 'verify\nx\n' |
811 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
812 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
813 -Ssmime-sign -Sfrom=test@localhost \
814 -Sbatch-exit-on-error -R \
815 -f ./VERIFY >/dev/null 2>&1
816 if [ $? -eq 0 ]; then
817 printf 'ok\n'
818 else
819 ESTAT=1
820 printf 'error: verification failed\n'
821 ${rm} -f ./VERIFY ./tkey.pem ./tcert.pem ./tpair.pem
822 return
824 ${rm} -rf ./VERIFY
826 # (signing +) encryption / decryption
827 ${cat} <<-_EOT > ./tsendmail.sh
828 #!/bin/sh -
829 (echo 'From S-Postman Thu May 10 20:40:54 2012' && ${cat}) > ./ENCRYPT
830 _EOT
831 chmod 0755 ./tsendmail.sh
833 printf "behave:s/mime:encrypt+sign/decrypt+verify: "
834 echo bla |
835 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
836 -Ssmime-force-encryption \
837 -Ssmime-encrypt-recei@ver.com=./tpair.pem \
838 -Ssendmail=./tsendmail.sh \
839 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
840 -Ssmime-sign -Sfrom=test@localhost \
841 -s 'S/MIME test' recei@ver.com
842 # TODO CHECK
843 printf 'decrypt ./DECRYPT\nfi ./DECRYPT\nverify\nx\n' |
844 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
845 -Ssmime-force-encryption \
846 -Ssmime-encrypt-recei@ver.com=./tpair.pem \
847 -Ssendmail=./tsendmail.sh \
848 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
849 -Ssmime-sign -Sfrom=test@localhost \
850 -Sbatch-exit-on-error -R \
851 -f ./ENCRYPT >/dev/null 2>&1
852 if [ $? -eq 0 ]; then
853 printf 'ok\n'
854 else
855 ESTAT=1
856 printf 'error: decryption+verification failed\n'
858 ${sed} -e '/^X-Decoding-Date/d' \
859 -e \
860 '/^Content-Disposition: attachment; filename="smime.p7s"/,/^-- /d' \
861 < ./DECRYPT > ./ENCRYPT
862 cksum_test ".. checksum of decrypted content" "./ENCRYPT" '2838023744 515'
864 ${rm} -f ./DECRYPT
865 printf "behave:s/mime:encrypt/decrypt: "
866 echo bla |
867 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
868 -Ssmime-force-encryption \
869 -Ssmime-encrypt-recei@ver.com=./tpair.pem \
870 -Ssendmail=./tsendmail.sh \
871 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
872 -Sfrom=test@localhost \
873 -s 'S/MIME test' recei@ver.com
874 printf 'decrypt ./DECRYPT\nx\n' |
875 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
876 -Ssmime-force-encryption \
877 -Ssmime-encrypt-recei@ver.com=./tpair.pem \
878 -Ssendmail=./tsendmail.sh \
879 -Ssmime-ca-file=./tcert.pem -Ssmime-sign-cert=./tpair.pem \
880 -Sfrom=test@localhost \
881 -Sbatch-exit-on-error -R \
882 -f ./ENCRYPT >/dev/null 2>&1
883 if [ $? -eq 0 ]; then
884 printf 'ok\n'
885 else
886 ESTAT=1
887 printf 'error: decryption failed\n'
888 # FALLTHRU
890 ${sed} -e '/^X-Decoding-Date/d' \
891 < ./DECRYPT > ./ENCRYPT
892 cksum_test ".. checksum of decrypted content" "./ENCRYPT" '2279047916 300'
894 ${rm} -f ./tsendmail.sh ./ENCRYPT ./DECRYPT \
895 ./tkey.pem ./tcert.pem ./tpair.pem
898 # t_content()
899 # Some basic tests regarding correct sending of mails, via STDIN / -t / -q,
900 # including basic MIME Content-Transfer-Encoding correctness (quoted-printable)
901 # Note we unfortunately need to place some statements without proper
902 # indentation because of continuation problems
903 t_content() {
904 ${rm} -f "${BODY}" "${MBOX}"
906 # MIME encoding (QP) stress message body
907 printf \
908 'Ich bin eine DÖS-Datäi mit sehr langen Zeilen und auch '\
909 'sonst bin ich ganz schön am Schleudern, da kannste denke '\
910 "wasde willst, gelle, gelle, gelle, gelle, gelle.\r\n"\
911 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst \r\n"\
912 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 1\r\n"\
913 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 12\r\n"\
914 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 123\r\n"\
915 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 1234\r\n"\
916 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 12345\r\n"\
917 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 123456\r\n"\
918 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 1234567\r\n"\
919 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 12345678\r\n"\
920 "Ich bin eine DÖS-Datäi mit langen Zeilen und auch sonst 123456789\r\n"\
921 "Unn ausserdem habe ich trailing SP/HT/SP/HT whitespace \r\n"\
922 "Unn ausserdem habe ich trailing HT/SP/HT/SP whitespace \r\n"\
923 "auf den zeilen vorher.\r\n"\
924 "From am Zeilenbeginn und From der Mitte gibt es auch.\r\n"\
925 ".\r\n"\
926 "Die letzte Zeile war nur ein Punkt.\r\n"\
927 "..\r\n"\
928 "Das waren deren zwei.\r\n"\
929 " \r\n"\
930 "Die letzte Zeile war ein Leerschritt.\n"\
931 "=VIER = EQUAL SIGNS=ON A LINE=\r\n"\
932 "Prösterchen.\r\n"\
933 ".\n"\
934 "Die letzte Zeile war nur ein Punkt, mit Unix Zeilenende.\n"\
935 "..\n"\
936 "Das waren deren zwei. ditto.\n"\
937 "Prösterchen.\n"\
938 "Unn ausseerdem habe ich trailing SP/HT/SP/HT whitespace \n"\
939 "Unn ausseerdem habe ich trailing HT/SP/HT/SP whitespace \n"\
940 "auf den zeilen vorher.\n"\
941 "ditto.\n"\
942 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.\n"\
943 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.1"\
944 "\n"\
945 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
946 "\n"\
947 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
948 "3\n"\
949 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
950 "34\n"\
951 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
952 "345\n"\
953 "Ich bin eine ziemlich lange, steile, scharfe Zeile mit Unix Zeilenende.12"\
954 "3456\n"\
955 "=VIER = EQUAL SIGNS=ON A LINE=\n"\
956 " \n"\
957 "Die letzte Zeile war ein Leerschritt.\n"\
958 ' '\
959 > "${BODY}"
961 # MIME encoding (QP) stress message subject
962 SUB="Äbrä Kä?dä=brö Fü?di=bus? \
963 adadaddsssssssddddddddddddddddddddd\
964 ddddddddddddddddddddddddddddddddddd\
965 ddddddddddddddddddddddddddddddddddd\
966 dddddddddddddddddddd Hallelulja? Od\
967 er?? eeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
968 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\
969 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee f\
970 fffffffffffffffffffffffffffffffffff\
971 fffffffffffffffffffff ggggggggggggg\
972 ggggggggggggggggggggggggggggggggggg\
973 ggggggggggggggggggggggggggggggggggg\
974 ggggggggggggggggggggggggggggggggggg\
975 gggggggggggggggg"
977 # Three tests for MIME encodign and (a bit) content classification.
978 # At the same time testing -q FILE, < FILE and -t FILE
980 # TODO Note: because of our weird putline() handling in <-> collect.c
981 ${rm} -f "${MBOX}"
982 < "${BODY}" MAILRC=/dev/null \
983 "${SNAIL}" -nSstealthmua -Sexpandaddr -a "${BODY}" -s "${SUB}" "${MBOX}"
984 cksum_test content:001-0 "${MBOX}" '3498258986 5631'
986 ${rm} -f "${MBOX}"
987 < "${BODY}" MAILRC=/dev/null \
988 "${SNAIL}" ${ARGS} -Snodot -a "${BODY}" -s "${SUB}" "${MBOX}"
989 cksum_test content:001 "${MBOX}" '3916146590 5630'
991 ${rm} -f "${MBOX}"
992 < /dev/null MAILRC=/dev/null \
993 "${SNAIL}" ${ARGS} -a "${BODY}" -s "${SUB}" \
994 -q "${BODY}" "${MBOX}"
995 cksum_test content:002 "${MBOX}" '3498258986 5631'
997 ${rm} -f "${MBOX}"
998 ( echo "To: ${MBOX}" && echo "Subject: ${SUB}" && echo &&
999 ${cat} "${BODY}"
1000 ) | MAILRC=/dev/null "${SNAIL}" ${ARGS} -Snodot -a "${BODY}" -t
1001 cksum_test content:003 "${MBOX}" '3916146590 5630'
1003 # Test for [260e19d] (Juergen Daubert)
1004 ${rm} -f "${MBOX}"
1005 echo body | MAILRC=/dev/null "${SNAIL}" ${ARGS} "${MBOX}"
1006 cksum_test content:004 "${MBOX}" '4140682175 72'
1008 # Sending of multiple mails in a single invocation
1009 ${rm} -f "${MBOX}"
1010 ( printf "m ${MBOX}\n~s subject1\nE-Mail Körper 1\n.\n" &&
1011 printf "m ${MBOX}\n~s subject2\nEmail body 2\n.\n" &&
1012 echo x
1013 ) | MAILRC=/dev/null "${SNAIL}" ${ARGS}
1014 cksum_test content:005 "${MBOX}" '3503215815 245'
1016 ## $BODY CHANGED
1018 # "Test for" [d6f316a] (Gavin Troy)
1019 ${rm} -f "${MBOX}"
1020 printf "m ${MBOX}\n~s subject1\nEmail body\n.\nfi ${MBOX}\np\nx\n" |
1021 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1022 -Spipe-text/plain="${cat}" > "${BODY}"
1023 ${sed} -e 1d < "${BODY}" > "${MBOX}"
1024 cksum_test content:006 "${MBOX}" '11112309 106'
1026 # "Test for" [c299c45] (Peter Hofmann) TODO shouldn't end up QP-encoded?
1027 # TODO Note: because of our weird putline() handling in <-> collect.c
1028 ${rm} -f "${MBOX}"
1029 LC_ALL=C ${awk} 'BEGIN{
1030 for(i = 0; i < 10000; ++i)
1031 printf "\xC3\xBC"
1032 #printf "\xF0\x90\x87\x90"
1033 }' |
1034 MAILRC=/dev/null "${SNAIL}" -nSstealthmua -Sexpandaddr \
1035 -s TestSubject "${MBOX}"
1036 cksum_test content:007-0 "${MBOX}" '2747333583 61729'
1038 ${rm} -f "${MBOX}"
1039 LC_ALL=C ${awk} 'BEGIN{
1040 for(i = 0; i < 10000; ++i)
1041 printf "\xC3\xBC"
1042 #printf "\xF0\x90\x87\x90"
1043 }' |
1044 MAILRC=/dev/null "${SNAIL}" ${ARGS} -s TestSubject "${MBOX}"
1045 cksum_test content:007 "${MBOX}" '3343002941 61728'
1047 ## Test some more corner cases for header bodies (as good as we can today) ##
1050 ${rm} -f "${MBOX}"
1051 echo |
1052 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1053 -s 'a̲b̲c̲d̲e̲f̲h̲i̲k̲l̲m̲n̲o̲r̲s̲t̲u̲v̲w̲x̲z̲a̲b̲c̲d̲e̲f̲h̲i̲k̲l̲m̲n̲o̲r̲s̲t̲u̲v̲w̲x̲z̲' \
1054 "${MBOX}"
1055 cksum_test content:008 "${MBOX}" '3872015771 288'
1057 # Single word (overlong line split -- bad standard! Requires injection of
1058 # artificial data!! Bad can be prevented by using RFC 2047 encoding)
1059 ${rm} -f "${MBOX}"
1060 i=`LC_ALL=C ${awk} 'BEGIN{for(i=0; i<92; ++i) printf "0123456789_"}'`
1061 echo | MAILRC=/dev/null "${SNAIL}" ${ARGS} -s "${i}" "${MBOX}"
1062 cksum_test content:009 "${MBOX}" '2048460448 1631'
1064 # Combination of encoded words, space and tabs of varying sort
1065 ${rm} -f "${MBOX}"
1066 echo | MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1067 -s "1Abrä Kaspas1 2Abra Katä b_kaspas2 \
1068 3Abrä Kaspas3 4Abrä Kaspas4 5Abrä Kaspas5 \
1069 6Abra Kaspas6 7Abrä Kaspas7 8Abra Kaspas8 \
1070 9Abra Kaspastäb4-3 10Abra Kaspas1 _ 11Abra Katäb1 \
1071 12Abra Kadabrä1 After Tab after Täb this is NUTS" \
1072 "${MBOX}"
1073 cksum_test content:010 "${MBOX}" '1272213842 504'
1075 # Overlong multibyte sequence that must be forcefully split
1076 # todo This works even before v15.0, but only by accident
1077 ${rm} -f "${MBOX}"
1078 echo | MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1079 -s "✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄\
1080 ✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄\
1081 ✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄✄" \
1082 "${MBOX}"
1083 cksum_test content:011 "${MBOX}" '2972351879 572'
1085 # Trailing WS
1086 ${rm} -f "${MBOX}"
1087 echo |
1088 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1089 -s "1-1 B2 B3 B4 B5 B6 B\
1090 1-2 B2 B3 B4 B5 B6 B\
1091 1-3 B2 B3 B4 B5 B6 B\
1092 1-4 B2 B3 B4 B5 B6 B\
1093 1-5 B2 B3 B4 B5 B6 B\
1094 1-6 B2 B3 B4 B5 B6 " \
1095 "${MBOX}"
1096 cksum_test content:012 "${MBOX}" '1276108207 271'
1098 # Leading and trailing WS
1099 ${rm} -f "${MBOX}"
1100 echo |
1101 MAILRC=/dev/null "${SNAIL}" ${ARGS} \
1102 -s " 2-1 B2 B3 B4 B5 B6 B\
1103 1-2 B2 B3 B4 B5 B6 B\
1104 1-3 B2 B3 B4 B5 B6 B\
1105 1-4 B2 B3 B4 B5 B6 " \
1106 "${MBOX}"
1107 cksum_test content:013 "${MBOX}" '3677630181 210'
1109 # Quick'n dirty RFC 2231 test; i had more when implementing it, but until we
1110 # have a (better) test framework materialize a quick shot
1111 ${rm} -f "${MBOX}"
1112 : > "ma'ger.txt"
1113 : > "mä'ger.txt"
1114 : > 'diet\ is \curd.txt'
1115 : > diet \"is\" curd.txt
1116 : > höde-tröge.txt
1117 : > höde__tröge__müde__dätte__hätte__vülle__gülle__äse__äße__säuerliche__kräuter__österliche__grüße__mäh.txt
1118 : > höde__tröge__müde__dätte__hätte__vuelle__guelle__aese__aesse__sauerliche__kräuter__österliche__grüße__mäh.txt
1119 : > hööööööööööööööööö_nöööööööööööööööööööööö_düüüüüüüüüüüüüüüüüüü_bäääääääääääääääääääääääh.txt
1120 : > ✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆.txt
1121 echo bla |
1122 MAILRC=/dev/null "${SNAIL}" ${ARGS} -Snodot \
1123 -a "ma'ger.txt" -a "mä'ger.txt" \
1124 -a 'diet\\\ is\ \\curd.txt' -a diet \"is\" curd.txt \
1125 -a höde-tröge.txt \
1126 -a höde__tröge__müde__dätte__hätte__vülle__gülle__äse__äße__säuerliche__kräuter__österliche__grüße__mäh.txt \
1127 -a höde__tröge__müde__dätte__hätte__vuelle__guelle__aese__aesse__sauerliche__kräuter__österliche__grüße__mäh.txt \
1128 -a hööööööööööööööööö_nöööööööööööööööööööööö_düüüüüüüüüüüüüüüüüüü_bäääääääääääääääääääääääh.txt \
1129 -a ✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆.txt \
1130 "${MBOX}"
1131 ${rm} -f "ma'ger.txt" "mä'ger.txt" 'diet\ is \curd.txt' \
1132 diet \"is\" curd.txt höde-tröge.txt \
1133 höde__tröge__müde__dätte__hätte__vülle__gülle__äse__äße__säuerliche__kräuter__österliche__grüße__mäh.txt \
1134 höde__tröge__müde__dätte__hätte__vuelle__guelle__aese__aesse__sauerliche__kräuter__österliche__grüße__mäh.txt \
1135 hööööööööööööööööö_nöööööööööööööööööööööö_düüüüüüüüüüüüüüüüüüü_bäääääääääääääääääääääääh.txt \
1136 ✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆✆.txt
1137 cksum_test content:14 "${MBOX}" '1106643854 2453'
1138 # `resend' test
1139 printf "Resend ${BODY}\nx\n" |
1140 MAILRC=/dev/null "${SNAIL}" ${ARGS} -f "${MBOX}"
1141 cksum_test content:14-2 "${MBOX}" '1106643854 2453'
1143 ${rm} -f "${BODY}" "${MBOX}"
1146 t_all() {
1147 if have_feat DEVEL; then
1148 ARGS="${ARGS} -Smemdebug"
1149 export ARGS
1151 t_behave
1152 t_content
1155 if [ -z "${CHECK_ONLY}" ]; then
1156 cc_all_configs
1157 else
1158 t_all
1161 [ ${ESTAT} -eq 0 ] && echo Ok || echo >&2 'Errors occurred'
1163 exit ${ESTAT}
1164 # s-sh-mode