]> git.notmuchmail.org Git - notmuch/blob - test/thread-replies
test: add tests for the handling of References and In-Reply-To headers
[notmuch] / test / thread-replies
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2013 Aaron Ecay
4 #
5
6 test_description='test of proper handling of in-reply-to and references headers'
7
8 # This test makes sure that the thread structure in the notmuch
9 # database is constructed properly, even in the presence of
10 # non-RFC-compliant headers'
11
12 . ./test-lib.sh
13
14 test_begin_subtest "Use References when In-Reply-To is broken"
15 test_subtest_known_broken
16 add_message '[id]="foo@one.com"' \
17     '[subject]=one'
18 add_message '[in-reply-to]="mumble"' \
19     '[references]="<foo@one.com>"' \
20     '[subject]="Re: one"'
21 output=$(notmuch show --format=json 'subject:one' | notmuch_json_show_sanitize)
22 expected='[[[{"id": "foo@one.com",
23  "match": true,
24  "excluded": false,
25  "filename": "YYYYY",
26  "timestamp": 978709437,
27  "date_relative": "2001-01-05",
28  "tags": ["inbox", "unread"],
29  "headers": {"Subject": "one",
30  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
31  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
32  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
33  "body": [{"id": 1,
34  "content-type": "text/plain",
35  "content": "This is just a test message (#1)\n"}]},
36  [[{"id": "msg-002@notmuch-test-suite",
37  "match": true, "excluded": false,
38  "filename": "YYYYY",
39  "timestamp": 978709437, "date_relative": "2001-01-05",
40  "tags": ["inbox", "unread"], "headers": {"Subject": "Re: one",
41  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
42  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
43  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
44  "body": [{"id": 1, "content-type": "text/plain",
45  "content": "This is just a test message (#2)\n"}]}, []]]]]]'
46 expected=`echo "$expected" | notmuch_json_show_sanitize`
47 test_expect_equal_json "$output" "$expected"
48
49 test_begin_subtest "Prefer References to In-Reply-To"
50 test_subtest_known_broken
51 add_message '[id]="foo@two.com"' \
52     '[subject]=two'
53 add_message '[in-reply-to]="<bar@baz.com>"' \
54     '[references]="<foo@two.com>"' \
55     '[subject]="Re: two"'
56 output=$(notmuch show --format=json 'subject:two' | notmuch_json_show_sanitize)
57 expected='[[[{"id": "foo@two.com",
58  "match": true, "excluded": false,
59  "filename": "YYYYY",
60  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
61  "headers": {"Subject": "two",
62  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
63  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
64  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
65  "body": [{"id": 1, "content-type": "text/plain",
66  "content": "This is just a test message (#3)\n"}]},
67  [[{"id": "msg-004@notmuch-test-suite", "match": true, "excluded": false,
68  "filename": "YYYYY",
69  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
70  "headers": {"Subject": "Re: two",
71  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
72  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
73  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
74  "body": [{"id": 1,
75  "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},
76  []]]]]]'
77 expected=`echo "$expected" | notmuch_json_show_sanitize`
78 test_expect_equal_json "$output" "$expected"
79
80 test_begin_subtest "Use In-Reply-To when no References"
81 add_message '[id]="foo@three.com"' \
82     '[subject]="three"'
83 add_message '[in-reply-to]="<foo@three.com>"' \
84     '[subject]="Re: three"'
85 output=$(notmuch show --format=json 'subject:three' | notmuch_json_show_sanitize)
86 expected='[[[{"id": "foo@three.com", "match": true, "excluded": false,
87  "filename": "YYYYY",
88  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
89  "headers": {"Subject": "three",
90  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
91  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
92  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
93  "content-type": "text/plain", "content": "This is just a test message (#5)\n"}]},
94  [[{"id": "msg-006@notmuch-test-suite", "match": true, "excluded": false,
95  "filename": "YYYYY",
96  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
97  "headers": {"Subject": "Re: three",
98  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
99  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
100  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
101  "content-type": "text/plain", "content": "This is just a test message (#6)\n"}]},
102  []]]]]]'
103 expected=`echo "$expected" | notmuch_json_show_sanitize`
104 test_expect_equal_json "$output" "$expected"
105
106 test_begin_subtest "Use last Reference"
107 test_subtest_known_broken
108 add_message '[id]="foo@four.com"' \
109     '[subject]="four"'
110 add_message '[id]="bar@four.com"' \
111     '[subject]="not-four"'
112 add_message '[in-reply-to]="<baz@four.com>"' \
113     '[references]="<baz@four.com> <foo@four.com>"' \
114     '[subject]="neither"'
115 output=$(notmuch show --format=json 'subject:four' | notmuch_json_show_sanitize)
116 expected='[[[{"id": "foo@four.com", "match": true, "excluded": false,
117  "filename": "YYYYY",
118  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
119  "headers": {"Subject": "four",
120  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
121  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
122  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
123  "content-type": "text/plain", "content": "This is just a test message (#7)\n"}]},
124  [[{"id": "msg-009@notmuch-test-suite", "match": false, "excluded": false,
125  "filename": "YYYYY",
126  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
127  "headers": {"Subject": "neither",
128  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
129  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
130  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
131  "content-type": "text/plain", "content": "This is just a test message (#9)\n"}]},
132  []]]]], [[{"id": "bar@four.com", "match": true, "excluded": false,
133  "filename": "YYYYY",
134  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
135  "headers": {"Subject": "not-four",
136  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
137  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
138  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
139  "content-type": "text/plain", "content": "This is just a test message (#8)\n"}]}, []]]]'
140 expected=`echo "$expected" | notmuch_json_show_sanitize`
141 test_expect_equal_json "$output" "$expected"
142
143
144 test_done