3 # Copyright (c) 2013 Aaron Ecay
6 test_description='test of proper handling of in-reply-to and references headers'
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'
14 test_begin_subtest "Use References when In-Reply-To is broken"
15 add_message '[id]="foo@one.com"' \
17 add_message '[in-reply-to]="mumble"' \
18 '[references]="<foo@one.com>"' \
20 output=$(notmuch show --format=json 'subject:one' | notmuch_json_show_sanitize)
21 expected='[[[{"id": "foo@one.com",
25 "timestamp": 978709437,
26 "date_relative": "2001-01-05",
27 "tags": ["inbox", "unread"],
28 "headers": {"Subject": "one",
29 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
30 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
31 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
33 "content-type": "text/plain",
34 "content": "This is just a test message (#1)\n"}]},
35 [[{"id": "msg-002@notmuch-test-suite",
36 "match": true, "excluded": false,
38 "timestamp": 978709437, "date_relative": "2001-01-05",
39 "tags": ["inbox", "unread"], "headers": {"Subject": "Re: one",
40 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
41 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
42 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
43 "body": [{"id": 1, "content-type": "text/plain",
44 "content": "This is just a test message (#2)\n"}]}, []]]]]]'
45 expected=`echo "$expected" | notmuch_json_show_sanitize`
46 test_expect_equal_json "$output" "$expected"
48 test_begin_subtest "Prefer References to In-Reply-To"
49 add_message '[id]="foo@two.com"' \
51 add_message '[in-reply-to]="<bar@baz.com>"' \
52 '[references]="<foo@two.com>"' \
54 output=$(notmuch show --format=json 'subject:two' | notmuch_json_show_sanitize)
55 expected='[[[{"id": "foo@two.com",
56 "match": true, "excluded": false,
58 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
59 "headers": {"Subject": "two",
60 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
61 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
62 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
63 "body": [{"id": 1, "content-type": "text/plain",
64 "content": "This is just a test message (#3)\n"}]},
65 [[{"id": "msg-004@notmuch-test-suite", "match": true, "excluded": false,
67 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
68 "headers": {"Subject": "Re: two",
69 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
70 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
71 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
73 "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},
75 expected=`echo "$expected" | notmuch_json_show_sanitize`
76 test_expect_equal_json "$output" "$expected"
78 test_begin_subtest "Use In-Reply-To when no References"
79 add_message '[id]="foo@three.com"' \
81 add_message '[in-reply-to]="<foo@three.com>"' \
82 '[subject]="Re: three"'
83 output=$(notmuch show --format=json 'subject:three' | notmuch_json_show_sanitize)
84 expected='[[[{"id": "foo@three.com", "match": true, "excluded": false,
86 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
87 "headers": {"Subject": "three",
88 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
89 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
90 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
91 "content-type": "text/plain", "content": "This is just a test message (#5)\n"}]},
92 [[{"id": "msg-006@notmuch-test-suite", "match": true, "excluded": false,
94 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
95 "headers": {"Subject": "Re: three",
96 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
97 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
98 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
99 "content-type": "text/plain", "content": "This is just a test message (#6)\n"}]},
101 expected=`echo "$expected" | notmuch_json_show_sanitize`
102 test_expect_equal_json "$output" "$expected"
104 test_begin_subtest "Use last Reference"
105 add_message '[id]="foo@four.com"' \
107 add_message '[id]="bar@four.com"' \
108 '[subject]="not-four"'
109 add_message '[in-reply-to]="<baz@four.com>"' \
110 '[references]="<baz@four.com> <foo@four.com>"' \
111 '[subject]="neither"'
112 output=$(notmuch show --format=json 'subject:four' | notmuch_json_show_sanitize)
113 expected='[[[{"id": "foo@four.com", "match": true, "excluded": false,
115 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
116 "headers": {"Subject": "four",
117 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
118 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
119 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
120 "content-type": "text/plain", "content": "This is just a test message (#7)\n"}]},
121 [[{"id": "msg-009@notmuch-test-suite", "match": false, "excluded": false,
123 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
124 "headers": {"Subject": "neither",
125 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
126 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
127 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
128 "content-type": "text/plain", "content": "This is just a test message (#9)\n"}]},
129 []]]]], [[{"id": "bar@four.com", "match": true, "excluded": false,
131 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
132 "headers": {"Subject": "not-four",
133 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
134 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
135 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
136 "content-type": "text/plain", "content": "This is just a test message (#8)\n"}]}, []]]]'
137 expected=`echo "$expected" | notmuch_json_show_sanitize`
138 test_expect_equal_json "$output" "$expected"