Strip comments from trailers for stg mail --auto
[stgit.git] / t / t1900-mail.sh
blob3abf414017f22822cc109fca950bc3c95ebcdb39
1 #!/bin/sh
2 # Copyright (c) 2006 Karl Hasselström
3 test_description='Test the mail command'
4 . ./test-lib.sh
6 test_expect_success 'Initialize the StGIT repository' '
7 git config stgit.sender "A U Thor <author@example.com>" &&
8 test_commit_bulk --message="Patch %s" --filename=foo.txt --contents="line %s" 5 &&
9 stg init &&
10 stg uncommit -n 5 foo
13 test_expect_success 'Ensure --all and --edit-cover play nice together' '
14 stg mail --to="Inge Ström <inge@example.com>" --all --edit-cover -m \
15 -t $STG_ROOT/stgit/templates/patchmail.tmpl > mbox0
18 test_expect_success 'Put all the patches in an mbox' '
19 stg mail --to="Inge Ström <inge@example.com>" -a -m \
20 -t $STG_ROOT/stgit/templates/patchmail.tmpl > mbox0
23 test_expect_success 'Import the mbox and compare' '
24 t1=$(git cat-file -p $(stg id) | grep ^tree)
25 stg pop -a &&
26 stg import -M mbox0 &&
27 t2=$(git cat-file -p $(stg id) | grep ^tree) &&
28 [ "$t1" = "$t2" ]
31 test_expect_success 'Put all the patches in an mbox with patch attachments' '
32 stg mail --to="Inge Ström <inge@example.com>" --attach -a -m > mbox1
35 test_expect_success 'Import the mbox containing patch attachments and compare' '
36 t1=$(git cat-file -p $(stg id) | grep ^tree)
37 stg pop -a &&
38 stg import -M mbox1 &&
39 t2=$(git cat-file -p $(stg id) | grep ^tree) &&
40 [ "$t1" = "$t2" ]
43 test_expect_success 'Attach patches inline' '
44 stg mail --to="Inge Ström <inge@example.com>" --attach-inline -a -m > mbox2
47 test_expect_success 'Import mbox containing inline attachments and compare' '
48 t1=$(git cat-file -p $(stg id) | grep ^tree)
49 stg pop -a &&
50 stg import -M mbox1 &&
51 t2=$(git cat-file -p $(stg id) | grep ^tree) &&
52 test "$t1" = "$t2"
55 test_expect_success 'Check the To:, Cc: and Bcc: headers' '
56 stg mail --to=a@a --cc="b@b, c@c" --bcc=d@d $(stg top) -m > mbox &&
57 test "$(cat mbox | grep -e "^To:")" = "To: a@a" &&
58 test "$(cat mbox | grep -e "^Cc:")" = "Cc: b@b, c@c" &&
59 test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: d@d"
62 test_expect_success 'Check the --auto option' '
63 stg edit --sign &&
64 stg mail --to=a@a --cc="b@b, c@c" --bcc=d@d --auto $(stg top) -m > mbox &&
65 test "$(cat mbox | grep -e "^To:")" = "To: a@a" &&
66 grep -E "^Cc: (C =\?utf-8\?b\?w5M=\?= Mitter|=\?utf-8\?q\?C_=C3=93_Mitter\?=) <committer@example.com>, b@b, c@c$" mbox &&
67 test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: d@d"
70 test_expect_success 'Check the e-mail address duplicates' '
71 stg mail --to="a@a, b b <b@b>" --cc="b@b, c@c" \
72 --bcc="c@c, d@d, committer@example.com" --auto $(stg top) -m > mbox &&
73 test "$(cat mbox | grep -e "^To:")" = "To: a@a, b b <b@b>" &&
74 grep -E "^Cc: (C =\?utf-8\?b\?w5M=\?= Mitter|=\?utf-8\?q\?C_=C3=93_Mitter\?=) <committer@example.com>, c@c$" mbox &&
75 test "$(cat mbox | grep -e "^Bcc:")" = "Bcc: d@d"
78 test_expect_success 'Check --auto with commented Cc: realname and addr' '
79 stg edit -m "Patch 5
81 Cc: Some Body <someone@example.com> # v3.2.1
82 " &&
83 stg mail --auto $(stg top) -m > mbox &&
84 test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: Some Body <someone@example.com>"
87 test_expect_success 'Check --auto with commented Cc: addr only' '
88 stg edit -m "Patch 5
90 Cc: someone@example.com # v3.2.1
91 " &&
92 stg mail --auto $(stg top) -m > mbox &&
93 test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: someone@example.com"
96 test_expect_success 'Check --auto with no-space commented Cc: realname and addr' '
97 stg edit -m "Patch 5
99 Cc: Some Body <someone.2@example.com>#v3.2.1
100 " &&
101 stg mail --auto $(stg top) -m > mbox &&
102 test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: Some Body <someone.2@example.com>"
105 test_expect_success 'Check --auto with no-space commented Cc: addr only' '
106 stg edit -m "Patch 5
108 Cc: someone.3@example.com#v3.2.1
109 " &&
110 stg mail --auto $(stg top) -m > mbox &&
111 test "$(cat mbox | grep -e "^Cc:" | head -n 1)" = "Cc: someone.3@example.com"
114 test_expect_success 'Test no patches' '
115 command_error stg mail
118 test_expect_success 'Test no patches with --all' '
119 stg pop -a &&
120 command_error stg mail --all &&
121 stg push
124 test_expect_success 'Test empty patch' '
125 stg new -m "empty" &&
126 command_error stg mail empty &&
127 stg clean
130 test_expect_success 'Invalid --in-reply-to combinations' '
131 echo "$(command_error stg mail --in-reply-to=xxx --no-thread $(stg top) 2>&1)" | \
132 grep -e "in-reply-to option not allowed with" &&
133 echo "$(command_error stg mail --in-reply-to=xxx --unrelated $(stg top) 2>&1)" | \
134 grep -e "in-reply-to option not allowed with"
137 test_expect_success 'Invalid --cover option combos' '
138 echo "$(command_error stg mail --cover=cover.txt --unrelated $(stg top) 2>&1)" | \
139 grep -e "cover sending not allowed with --unrelated" &&
140 echo "$(command_error stg mail --edit-cover --unrelated $(stg top) 2>&1)" | \
141 grep -e "cover sending not allowed with --unrelated"
144 cat > cover.txt <<EOF
145 From: A U Thor <author@example.com>
146 Subject: Cover Test
148 A cover test.
151 test_expect_success 'User-specified cover file' '
152 stg mail -m --cover=cover.txt $(stg top) > mbox-cover &&
153 grep -e "Subject: Cover Test" mbox-cover &&
154 grep -e "From: A U Thor" mbox-cover
157 test_expect_success 'Edit cover' '
158 stg mail -m --edit-cover foo1 foo2 foo3 foo4 > cover.mbox &&
159 cat cover.mbox | grep -e "Subject: \[PATCH 0/4\] Series short description" &&
160 cat cover.mbox | \
161 grep -A3 -e "Patch 1" | \
162 grep -A2 -e "Patch 2" | \
163 grep -A1 -e "Patch 3" | \
164 grep -e "Patch 4"
167 test_done