]> git.cworth.org Git - notmuch/blob - test/T470-missing-headers.sh
lib/date: factor out date range parsing.
[notmuch] / test / T470-missing-headers.sh
1 #!/usr/bin/env bash
2 test_description='messages with missing headers'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 # Notmuch requires at least one of from, subject, or to or it will
6 # ignore the file.  Generate two messages so that together they cover
7 # all possible missing headers.  We also give one of the messages a
8 # date to ensure stable result ordering.
9
10 cat <<EOF > "${MAIL_DIR}/msg-2"
11 To: Notmuch Test Suite <test_suite@notmuchmail.org>
12 Date: Fri, 05 Jan 2001 15:43:57 +0000
13
14 Body
15 EOF
16
17 cat <<EOF > "${MAIL_DIR}/msg-1"
18 From: Notmuch Test Suite <test_suite@notmuchmail.org>
19
20 Body
21 EOF
22
23 NOTMUCH_NEW >/dev/null
24
25 test_begin_subtest "Search: text"
26 output=$(notmuch search '*' | notmuch_search_sanitize)
27 test_expect_equal "$output" "\
28 thread:XXX   2001-01-05 [1/1] ;  (inbox unread)
29 thread:XXX   1970-01-01 [1/1] Notmuch Test Suite;  (inbox unread)"
30
31 test_begin_subtest "Search: json"
32 output=$(notmuch search --format=json '*' | notmuch_search_sanitize)
33 test_expect_equal_json "$output" '
34 [
35     {
36         "authors": "",
37         "date_relative": "2001-01-05",
38         "matched": 1,
39         "subject": "",
40         "tags": [
41             "inbox",
42             "unread"
43         ],
44         "thread": "XXX",
45         "timestamp": 978709437,
46         "total": 1,
47         "query": ["id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161", null]
48     },
49     {
50         "authors": "Notmuch Test Suite",
51         "date_relative": "1970-01-01",
52         "matched": 1,
53         "subject": "",
54         "tags": [
55             "inbox",
56             "unread"
57         ],
58         "thread": "XXX",
59         "timestamp": 0,
60         "total": 1,
61         "query": ["id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334", null]
62     }
63 ]'
64
65 test_begin_subtest "Show: text"
66 output=$(notmuch show '*' | notmuch_show_sanitize)
67 test_expect_equal "$output" "\
68 \fmessage{ id:notmuch-sha1-7a6e4eac383ef958fcd3ebf2143db71b8ff01161 depth:0 match:1 excluded:0 filename:/XXX/mail/msg-2
69 \fheader{
70  (2001-01-05) (inbox unread)
71 Subject: (null)
72 From: (null)
73 To: Notmuch Test Suite <test_suite@notmuchmail.org>
74 Date: Fri, 05 Jan 2001 15:43:57 +0000
75 \fheader}
76 \fbody{
77 \fpart{ ID: 1, Content-type: text/plain
78 Body
79 \fpart}
80 \fbody}
81 \fmessage}
82 \fmessage{ id:notmuch-sha1-ca55943aff7a72baf2ab21fa74fab3d632401334 depth:0 match:1 excluded:0 filename:/XXX/mail/msg-1
83 \fheader{
84 Notmuch Test Suite <test_suite@notmuchmail.org> (1970-01-01) (inbox unread)
85 Subject: (null)
86 From: Notmuch Test Suite <test_suite@notmuchmail.org>
87 Date: Thu, 01 Jan 1970 00:00:00 +0000
88 \fheader}
89 \fbody{
90 \fpart{ ID: 1, Content-type: text/plain
91 Body
92 \fpart}
93 \fbody}
94 \fmessage}"
95
96 test_begin_subtest "Show: json"
97 output=$(notmuch show --format=json '*' | notmuch_json_show_sanitize)
98 expected=$(notmuch_json_show_sanitize <<EOF
99 [
100     [
101         [
102             {
103                 "body": [
104                     {
105                         "content": "Body\n",
106                         "content-type": "text/plain",
107                         "id": 1
108                     }
109                 ],
110                 "crypto": {},
111                 "date_relative": "2001-01-05",
112                 "excluded": false,
113                 "filename": ["YYYYY"],
114                 "headers": {
115                     "Date": "Fri, 05 Jan 2001 15:43:57 +0000",
116                     "From": "",
117                     "Subject": "",
118                     "To": "Notmuch Test Suite <test_suite@notmuchmail.org>"
119                 },
120                 "id": "XXXXX",
121                 "match": true,
122                 "tags": [
123                     "inbox",
124                     "unread"
125                 ],
126                 "timestamp": 978709437
127             },
128             []
129         ]
130     ],
131     [
132         [
133             {
134                 "body": [
135                     {
136                         "content": "Body\n",
137                         "content-type": "text/plain",
138                         "id": 1
139                     }
140                 ],
141                 "crypto": {},
142                 "date_relative": "1970-01-01",
143                 "excluded": false,
144                 "filename": ["YYYYY"],
145                 "headers": {
146                     "Date": "Thu, 01 Jan 1970 00:00:00 +0000",
147                     "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
148                     "Subject": ""
149                 },
150                 "id": "XXXXX",
151                 "match": true,
152                 "tags": [
153                     "inbox",
154                     "unread"
155                 ],
156                 "timestamp": 0
157             },
158             []
159         ]
160     ]
161 ]
162 EOF
163 )
164 test_expect_equal_json "$output" "$expected"
165
166 test_done