]> git.notmuchmail.org Git - notmuch/blob - test/emacs
test: use emacs_deliver_message in Emacs SMTP send test
[notmuch] / test / emacs
1 #!/usr/bin/env bash
2 test_description="emacs interface"
3 . test-lib.sh
4
5 EXPECTED=../emacs.expected-output
6
7 add_email_corpus
8
9 test_begin_subtest "Basic notmuch-hello view in emacs"
10 test_emacs '(notmuch-hello)
11             (test-output)'
12 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello
13
14 test_begin_subtest "Saved search with 0 results"
15 test_emacs '(setq notmuch-show-empty-saved-searches t)
16             (setq notmuch-saved-searches
17                   '\''(("inbox" . "tag:inbox")
18                        ("unread" . "tag:unread")
19                        ("empty" . "tag:doesnotexist")))
20             (notmuch-hello)
21             (test-output)'
22 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-with-empty
23
24 test_begin_subtest "No saved searches displayed (all with 0 results)"
25 test_emacs '(setq notmuch-saved-searches
26                   '\''(("empty" . "tag:doesnotexist")))
27             (notmuch-hello)
28             (test-output)'
29 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-no-saved-searches
30
31 test_begin_subtest "Basic notmuch-search view in emacs"
32 test_emacs '(notmuch-search "tag:inbox")
33             (notmuch-test-wait)
34             (test-output)'
35 test_expect_equal_file OUTPUT $EXPECTED/notmuch-search-tag-inbox
36
37 test_begin_subtest "Navigation of notmuch-hello to search results"
38 test_emacs '(notmuch-hello)
39             (goto-char (point-min))
40             (re-search-forward "inbox")
41             (widget-button-press (point))
42             (notmuch-test-wait)
43             (test-output)'
44 test_expect_equal_file OUTPUT $EXPECTED/notmuch-hello-view-inbox
45
46 test_begin_subtest "Basic notmuch-show view in emacs"
47 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
48 test_emacs "(notmuch-show \"$maildir_storage_thread\")
49             (test-output)"
50 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
51
52 test_begin_subtest "notmuch-show for message with invalid From"
53 add_message "[subject]=\"message-with-invalid-from\"" \
54             "[from]=\"\\\"Invalid \\\" From\\\" <test_suite@notmuchmail.org>\""
55 thread=$(notmuch search --output=threads subject:message-with-invalid-from)
56 test_emacs "(notmuch-show \"$thread\")
57             (test-output)"
58 cat <<EOF >EXPECTED
59 "Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
60 Subject: message-with-invalid-from
61 To: Notmuch Test Suite <test_suite@notmuchmail.org>
62 Date: Tue, 05 Jan 2001 15:43:57 -0000
63
64 This is just a test message (#1)
65 EOF
66 test_expect_equal_file OUTPUT EXPECTED
67
68 test_begin_subtest "Navigation of notmuch-search to thread view"
69 test_emacs '(notmuch-search "tag:inbox")
70             (notmuch-test-wait)
71             (goto-char (point-min))
72             (re-search-forward "Working with Maildir")
73             (notmuch-search-show-thread)
74             (notmuch-test-wait)
75             (test-output)'
76 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
77
78 test_begin_subtest "Add tag from search view"
79 os_x_darwin_thread=$(notmuch search --output=threads id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com)
80 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
81             (notmuch-test-wait)
82             (notmuch-search-add-tag \"tag-from-search-view\")"
83 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
84 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-search-view unread)"
85
86 test_begin_subtest "Remove tag from search view"
87 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
88             (notmuch-test-wait)
89             (notmuch-search-remove-tag \"tag-from-search-view\")"
90 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
91 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
92
93 test_begin_subtest "Add tag from notmuch-show view"
94 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
95             (notmuch-show-add-tag \"tag-from-show-view\")"
96 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
97 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-show-view unread)"
98
99 test_begin_subtest "Remove tag from notmuch-show view"
100 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
101             (notmuch-show-remove-tag \"tag-from-show-view\")"
102 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
103 test_expect_equal "$output" "thread:XXX   2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)"
104
105 test_begin_subtest "Message with .. in Message-Id:"
106 add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'
107 test_emacs '(notmuch-search "id:\"123..456@example\"")
108             (notmuch-test-wait)
109             (notmuch-search-add-tag "search-add")
110             (notmuch-search-add-tag "search-remove")
111             (notmuch-search-remove-tag "search-remove")
112             (notmuch-show "id:\"123..456@example\"")
113             (notmuch-test-wait)
114             (notmuch-show-add-tag "show-add")
115             (notmuch-show-add-tag "show-remove")
116             (notmuch-show-remove-tag "show-remove")'
117 output=$(notmuch search 'id:"123..456@example"' | notmuch_search_sanitize)
118 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message with .. in Message-Id (inbox search-add show-add)"
119
120 test_begin_subtest "Sending a message via (fake) SMTP"
121 emacs_deliver_message \
122     'Testing message sent via SMTP' \
123     'This is a test that messages are sent via SMTP' \
124     '(message-goto-to)
125      (kill-whole-line)
126      (insert "To: user@example.com\n")'
127 sed \
128     -e s',^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' \
129     -e s',^Message-ID: <.*>$,Message-ID: <XXX>,' < sent_message >OUTPUT
130 cat <<EOF >EXPECTED
131 From: Notmuch Test Suite <test_suite@notmuchmail.org>
132 To: user@example.com
133 Subject: Testing message sent via SMTP
134 Date: 01 Jan 2000 12:00:00 -0000
135 User-Agent: Notmuch/XXX Emacs/XXX
136 Message-ID: <XXX>
137 MIME-Version: 1.0
138 Content-Type: text/plain; charset=us-ascii
139
140 This is a test that messages are sent via SMTP
141 EOF
142 test_expect_equal_file OUTPUT EXPECTED
143
144 test_begin_subtest "Verify that sent messages are saved/searchable (via FCC)"
145 notmuch new > /dev/null
146 output=$(notmuch search 'subject:"testing message sent via SMTP"' | notmuch_search_sanitize)
147 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)"
148
149 test_begin_subtest "notmuch-fcc-dirs set to nil"
150 test_emacs "(setq notmuch-fcc-dirs nil)
151             (notmuch-mua-mail)
152             (test-output)"
153 cat <<EOF >EXPECTED
154 From: Notmuch Test Suite <test_suite@notmuchmail.org>
155 To: 
156 Subject: 
157 --text follows this line--
158 EOF
159 test_expect_equal_file OUTPUT EXPECTED
160
161 # Make another FCC maildir specific for the next test
162 mkdir -p mail/sent-string/cur
163 mkdir -p mail/sent-string/new
164 mkdir -p mail/sent-string/tmp
165
166 test_begin_subtest "notmuch-fcc-dirs set to a string"
167 test_emacs "(setq notmuch-fcc-dirs \"sent-string\")
168             (notmuch-mua-mail)
169             (test-output)"
170 cat <<EOF >EXPECTED
171 From: Notmuch Test Suite <test_suite@notmuchmail.org>
172 To: 
173 Subject: 
174 Fcc: ${MAIL_DIR}/sent-string
175 --text follows this line--
176 EOF
177 test_expect_equal_file OUTPUT EXPECTED
178
179 # Make more FCC maildirs specific for the next test
180 mkdir -p mail/sent-list-match/cur
181 mkdir -p mail/sent-list-match/new
182 mkdir -p mail/sent-list-match/tmp
183 mkdir -p mail/failure/cur
184 mkdir -p mail/failure/new
185 mkdir -p mail/failure/tmp
186
187 test_begin_subtest "notmuch-fcc-dirs set to a list (with match)"
188 test_emacs "(setq notmuch-fcc-dirs
189                   '((\"notmuchmail.org\" . \"sent-list-match\")
190                     (\".*\" . \"failure\")))
191             (notmuch-mua-mail)
192             (test-output)"
193 cat <<EOF >EXPECTED
194 From: Notmuch Test Suite <test_suite@notmuchmail.org>
195 To: 
196 Subject: 
197 Fcc: ${MAIL_DIR}/sent-list-match
198 --text follows this line--
199 EOF
200 test_expect_equal_file OUTPUT EXPECTED
201
202 # Make another FCC maildir specific for the next test
203 mkdir -p mail/sent-list-catch-all/cur
204 mkdir -p mail/sent-list-catch-all/new
205 mkdir -p mail/sent-list-catch-all/tmp
206  
207 test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)"
208 test_emacs "(setq notmuch-fcc-dirs
209                   '((\"example.com\" . \"failure\")
210                     (\".*\" . \"sent-list-catch-all\")))
211             (notmuch-mua-mail)
212             (test-output)"
213 cat <<EOF >EXPECTED
214 From: Notmuch Test Suite <test_suite@notmuchmail.org>
215 To: 
216 Subject: 
217 Fcc: ${MAIL_DIR}/sent-list-catch-all
218 --text follows this line--
219 EOF
220 test_expect_equal_file OUTPUT EXPECTED
221
222 test_begin_subtest "notmuch-fcc-dirs set to a list (no match)"
223 test_emacs "(setq notmuch-fcc-dirs
224                   '((\"example.com\" . \"failure\")
225                     (\"nomatchhere.net\" . \"failure\")))
226             (notmuch-mua-mail)
227             (test-output)"
228 cat <<EOF >EXPECTED
229 From: Notmuch Test Suite <test_suite@notmuchmail.org>
230 To: 
231 Subject: 
232 --text follows this line--
233 EOF
234 test_expect_equal_file OUTPUT EXPECTED
235
236 test_begin_subtest "Reply within emacs"
237 test_emacs '(notmuch-search "subject:\"testing message sent via SMTP\"")
238             (notmuch-test-wait)
239             (notmuch-search-reply-to-thread)
240             (test-output)'
241 sed -i -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' OUTPUT
242 cat <<EOF >EXPECTED
243 From: Notmuch Test Suite <test_suite@notmuchmail.org>
244 To: user@example.com
245 Subject: Re: Testing message sent via SMTP
246 In-Reply-To: <XXX>
247 Fcc: $(pwd)/mail/sent
248 --text follows this line--
249 On 01 Jan 2000 12:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
250 > This is a test that messages are sent via SMTP
251 EOF
252 test_expect_equal_file OUTPUT EXPECTED
253
254 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
255 # save as archive to test that Emacs does not re-compress .gz
256 echo ./attachment1.gz |
257 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
258             (notmuch-show-save-attachments)' > /dev/null 2>&1
259 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
260
261 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
262 # save as archive to test that Emacs does not re-compress .gz
263 echo ./attachment2.gz |
264 test_emacs '(notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5)' > /dev/null 2>&1
265 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
266
267 test_begin_subtest "View raw message within emacs"
268 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
269             (notmuch-show-view-raw-message)
270             (test-output)'
271 test_expect_equal_file OUTPUT $EXPECTED/raw-message-cf0c4d-52ad0a
272
273 test_begin_subtest "Hiding/showing signature in notmuch-show view"
274 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
275 test_emacs "(notmuch-show \"$maildir_storage_thread\")
276             (search-forward \"Click/Enter to show.\")
277             (button-activate (button-at (point)))
278             (search-backward \"Click/Enter to hide.\")
279             (button-activate (button-at (point)))
280             (test-output)"
281 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
282
283 test_begin_subtest "Detection and hiding of top-post quoting of message"
284 add_message '[subject]="The problem with top-posting"' \
285             [id]=top-post-target \
286             '[body]="A: Because it messes up the order in which people normally read text.
287 Q: Why is top-posting such a bad thing?
288 A: Top-posting.
289 Q: What is the most annoying thing in e-mail?"'
290 add_message '[from]="Top Poster <top@poster.com>"' \
291             [in-reply-to]=top-post-target \
292             [references]=top-post-target \
293             '[subject]="Re: The problem with top-posting"' \
294             '[body]="Thanks for the advice! I will be sure to put it to good use.
295
296 -Top Poster
297
298 ----- Original Message -----
299 From: Notmuch Test Suite <test_suite@notmuchmail.org>
300 To: Notmuch Test Suite <test_suite@notmuchmai.org>
301 Sent: Tue, 05 Jan 2001 15:43:57 -0000
302 Subject: The problem with top-posting
303
304 Q: Why is top-posting such a bad thing?
305 A: Top-posting.
306 Q: What is the most annoying thing in e-mail?"'
307 test_emacs "(notmuch-show \"top-posting\")
308             (test-visible-output)"
309 echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
310 Subject: The problem with top-posting
311 To: Notmuch Test Suite <test_suite@notmuchmail.org>
312 Date: Tue, 05 Jan 2001 15:43:57 -0000
313
314 A: Because it messes up the order in which people normally read text.
315 Q: Why is top-posting such a bad thing?
316 A: Top-posting.
317 Q: What is the most annoying thing in e-mail?
318 Top Poster <top@poster.com> (2001-01-05) (inbox unread)
319 Subject: Re: The problem with top-posting
320 To: Notmuch Test Suite <test_suite@notmuchmail.org>
321 Date: Tue, 05 Jan 2001 15:43:57 -0000
322
323 Thanks for the advice! I will be sure to put it to good use.
324
325 -Top Poster
326
327 [ 9-line hidden original message. Click/Enter to show. ]" > EXPECTED
328 test_expect_equal_file OUTPUT EXPECTED
329
330 test_begin_subtest "Hiding message in notmuch-show view"
331 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
332             (notmuch-show-toggle-message)
333             (test-visible-output)'
334 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
335
336 test_begin_subtest "Hiding message with visible citation in notmuch-show view"
337 test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
338             (search-forward "Click/Enter to show.")
339             (button-activate (button-at (point)))
340             (notmuch-show-toggle-message)
341             (test-visible-output)'
342 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-with-hidden-messages
343
344 test_done