mailinfo: handle in-body header continuations
[git/git.git] / t / t5100-mailinfo.sh
CommitLineData
4839c0b5
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git mailinfo and git mailsplit test'
4839c0b5
JH
7
8. ./test-lib.sh
9
10test_expect_success 'split sample box' \
bfdbee98 11 'git mailsplit -o. "$TEST_DIRECTORY"/t5100/sample.mbox >last &&
fc7b076d 12 last=$(cat last) &&
4839c0b5 13 echo total is $last &&
6b4b013f 14 test $(cat last) = 18'
4839c0b5 15
017678b4
JH
16check_mailinfo () {
17 mail=$1 opt=$2
18 mo="$mail$opt"
19 git mailinfo -u $opt msg$mo patch$mo <$mail >info$mo &&
20 test_cmp "$TEST_DIRECTORY"/t5100/msg$mo msg$mo &&
21 test_cmp "$TEST_DIRECTORY"/t5100/patch$mo patch$mo &&
22 test_cmp "$TEST_DIRECTORY"/t5100/info$mo info$mo
23}
24
25
6ffd3ec8 26for mail in 00*
4839c0b5 27do
bfdbee98 28 test_expect_success "mailinfo $mail" '
017678b4
JH
29 check_mailinfo $mail "" &&
30 if test -f "$TEST_DIRECTORY"/t5100/msg$mail--scissors
31 then
32 check_mailinfo $mail --scissors
d25e5159
LS
33 fi &&
34 if test -f "$TEST_DIRECTORY"/t5100/msg$mail--no-inbody-headers
35 then
36 check_mailinfo $mail --no-inbody-headers
8fb26872 37 fi &&
452dfbed
PB
38 if test -f "$TEST_DIRECTORY"/t5100/msg$mail--message-id
39 then
40 check_mailinfo $mail --message-id
41 fi
bfdbee98 42 '
4839c0b5
JH
43done
44
c32815f9
KS
45
46test_expect_success 'split box with rfc2047 samples' \
47 'mkdir rfc2047 &&
48 git mailsplit -orfc2047 "$TEST_DIRECTORY"/t5100/rfc2047-samples.mbox \
49 >rfc2047/last &&
fc7b076d 50 last=$(cat rfc2047/last) &&
c32815f9 51 echo total is $last &&
fc7b076d 52 test $(cat rfc2047/last) = 11'
c32815f9 53
6ffd3ec8 54for mail in rfc2047/00*
c32815f9
KS
55do
56 test_expect_success "mailinfo $mail" '
57 git mailinfo -u $mail-msg $mail-patch <$mail >$mail-info &&
58 echo msg &&
59 test_cmp "$TEST_DIRECTORY"/t5100/empty $mail-msg &&
60 echo patch &&
61 test_cmp "$TEST_DIRECTORY"/t5100/empty $mail-patch &&
62 echo info &&
63 test_cmp "$TEST_DIRECTORY"/t5100/rfc2047-info-$(basename $mail) $mail-info
64 '
65done
66
cce8d6fd
JS
67test_expect_success 'respect NULs' '
68
bfdbee98
JH
69 git mailsplit -d3 -o. "$TEST_DIRECTORY"/t5100/nul-plain &&
70 test_cmp "$TEST_DIRECTORY"/t5100/nul-plain 001 &&
cce8d6fd 71 (cat 001 | git mailinfo msg patch) &&
3fb0459b 72 test_line_count = 4 patch
cce8d6fd
JS
73
74'
75
9aa23094
JH
76test_expect_success 'Preserve NULs out of MIME encoded message' '
77
bfdbee98
JH
78 git mailsplit -d5 -o. "$TEST_DIRECTORY"/t5100/nul-b64.in &&
79 test_cmp "$TEST_DIRECTORY"/t5100/nul-b64.in 00001 &&
9aa23094 80 git mailinfo msg patch <00001 &&
bfdbee98 81 test_cmp "$TEST_DIRECTORY"/t5100/nul-b64.expect patch
9aa23094
JH
82
83'
84
e9d7d10a
JK
85test_expect_success 'mailinfo on from header without name works' '
86
87 mkdir info-from &&
88 git mailsplit -oinfo-from "$TEST_DIRECTORY"/t5100/info-from.in &&
89 test_cmp "$TEST_DIRECTORY"/t5100/info-from.in info-from/0001 &&
90 git mailinfo info-from/msg info-from/patch \
91 <info-from/0001 >info-from/out &&
92 test_cmp "$TEST_DIRECTORY"/t5100/info-from.expect info-from/out
93
94'
95
2da1f366
JK
96test_expect_success 'mailinfo finds headers after embedded From line' '
97 mkdir embed-from &&
98 git mailsplit -oembed-from "$TEST_DIRECTORY"/t5100/embed-from.in &&
99 test_cmp "$TEST_DIRECTORY"/t5100/embed-from.in embed-from/0001 &&
100 git mailinfo embed-from/msg embed-from/patch \
101 <embed-from/0001 >embed-from/out &&
102 test_cmp "$TEST_DIRECTORY"/t5100/embed-from.expect embed-from/out
103'
104
105test_expect_success 'mailinfo on message with quoted >From' '
106 mkdir quoted-from &&
107 git mailsplit -oquoted-from "$TEST_DIRECTORY"/t5100/quoted-from.in &&
108 test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.in quoted-from/0001 &&
109 git mailinfo quoted-from/msg quoted-from/patch \
110 <quoted-from/0001 >quoted-from/out &&
111 test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.expect quoted-from/msg
112'
113
c88098d7
EW
114test_expect_success 'mailinfo unescapes with --mboxrd' '
115 mkdir mboxrd &&
116 git mailsplit -omboxrd --mboxrd \
117 "$TEST_DIRECTORY"/t5100/sample.mboxrd >last &&
118 test x"$(cat last)" = x2 &&
119 for i in 0001 0002
120 do
121 git mailinfo mboxrd/msg mboxrd/patch \
122 <mboxrd/$i >mboxrd/out &&
123 test_cmp "$TEST_DIRECTORY"/t5100/${i}mboxrd mboxrd/msg
124 done &&
125 sp=" " &&
126 echo "From " >expect &&
127 echo "From " >>expect &&
128 echo >> expect &&
129 cat >sp <<-INPUT_END &&
130 From mboxrd Mon Sep 17 00:00:00 2001
131 From: trailing spacer <sp@example.com>
132 Subject: [PATCH] a commit with trailing space
133
134 From$sp
135 >From$sp
136
137 INPUT_END
138
139 git mailsplit -f2 -omboxrd --mboxrd <sp >last &&
140 test x"$(cat last)" = x1 &&
141 git mailinfo mboxrd/msg mboxrd/patch <mboxrd/0003 &&
142 test_cmp expect mboxrd/msg
143'
144
4839c0b5 145test_done