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