]> git.notmuchmail.org Git - notmuch/blob - test/emacs
fddb4a1ca15606c2dc81b572c7241374177b6134
[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             (princ (buffer-string))' >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             (princ (buffer-string))' >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             (princ (buffer-string))' >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             (princ (buffer-string))' >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             (princ (buffer-string))' >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             (princ (buffer-string))" >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 output=$(test_emacs "(notmuch-show \"$thread\") (princ (buffer-string))")
57 test_expect_equal "$output" \
58 '"Invalid " From" <test_suite@notmuchmail.org> (2001-01-05) (inbox)
59 Subject: message-with-invalid-from
60 To: Notmuch Test Suite <test_suite@notmuchmail.org>
61 Date: Tue, 05 Jan 2001 15:43:57 -0000
62
63 This is just a test message (#1)'
64
65 test_begin_subtest "Navigation of notmuch-search to thread view"
66 test_emacs '(notmuch-search "tag:inbox")
67             (notmuch-test-wait)
68             (goto-char (point-min))
69             (re-search-forward "Working with Maildir")
70             (notmuch-search-show-thread)
71             (notmuch-test-wait)
72             (princ (buffer-string))' >OUTPUT
73 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
74
75 test_begin_subtest "Add tag from search view"
76 os_x_darwin_thread=$(notmuch search --output=threads id:ddd65cda0911171950o4eea4389v86de9525e46052d3@mail.gmail.com)
77 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
78             (notmuch-test-wait)
79             (notmuch-search-add-tag \"tag-from-search-view\")"
80 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
81 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)"
82
83 test_begin_subtest "Remove tag from search view"
84 test_emacs "(notmuch-search \"$os_x_darwin_thread\")
85             (notmuch-test-wait)
86             (notmuch-search-remove-tag \"tag-from-search-view\")"
87 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
88 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)"
89
90 test_begin_subtest "Add tag from notmuch-show view"
91 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
92             (notmuch-show-add-tag \"tag-from-show-view\")"
93 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
94 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)"
95
96 test_begin_subtest "Remove tag from notmuch-show view"
97 test_emacs "(notmuch-show \"$os_x_darwin_thread\")
98             (notmuch-show-remove-tag \"tag-from-show-view\")"
99 output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize)
100 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)"
101
102 test_begin_subtest "Message with .. in Message-Id:"
103 add_message [id]=123..456@example '[subject]="Message with .. in Message-Id"'
104 test_emacs '(notmuch-search "id:\"123..456@example\"")
105             (notmuch-test-wait)
106             (notmuch-search-add-tag "search-add")
107             (notmuch-search-add-tag "search-remove")
108             (notmuch-search-remove-tag "search-remove")
109             (notmuch-show "id:\"123..456@example\"")
110             (notmuch-test-wait)
111             (notmuch-show-add-tag "show-add")
112             (notmuch-show-add-tag "show-remove")
113             (notmuch-show-remove-tag "show-remove")'
114 output=$(notmuch search 'id:"123..456@example"' | notmuch_search_sanitize)
115 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message with .. in Message-Id (inbox search-add show-add)"
116
117 test_begin_subtest "Sending a message via (fake) SMTP"
118
119 # Before we can send a message, we have to prepare the FCC maildir
120 mkdir -p mail/sent/cur
121 mkdir -p mail/sent/new
122 mkdir -p mail/sent/tmp
123
124 ../smtp-dummy sent_message &
125 smtp_dummy_pid=$!
126 test_emacs "(setq message-send-mail-function 'message-smtpmail-send-it)
127             (setq smtpmail-smtp-server \"localhost\")
128             (setq smtpmail-smtp-service \"25025\")
129             (notmuch-hello)
130             (notmuch-mua-mail)
131             (message-goto-to)
132             (insert \"user@example.com\nDate: Fri, 29 Mar 1974 10:00:00 -0000\")
133             (message-goto-subject)
134             (insert \"Testing message sent via SMTP\")
135             (message-goto-body)
136             (insert \"This is a test that messages are sent via SMTP\")
137             (message-send-and-exit)" >/dev/null 2>&1
138 wait ${smtp_dummy_pid}
139
140 sed \
141     -e s',^User-Agent: Notmuch/.* Emacs/.*,User-Agent: Notmuch/XXX Emacs/XXX,' \
142     -e s',^Message-ID: <.*>$,Message-ID: <XXX>,' < sent_message >OUTPUT
143 cat <<EOF >EXPECTED
144 From: Notmuch Test Suite <test_suite@notmuchmail.org>
145 To: user@example.com
146 Subject: Testing message sent via SMTP
147 Date: Fri, 29 Mar 1974 10:00:00 -0000
148 User-Agent: Notmuch/XXX Emacs/XXX
149 Message-ID: <XXX>
150 MIME-Version: 1.0
151 Content-Type: text/plain; charset=us-ascii
152
153 This is a test that messages are sent via SMTP
154 EOF
155 test_expect_equal_file OUTPUT EXPECTED
156
157 test_begin_subtest "Verify that sent messages are saved/searchable (via FCC)"
158 notmuch new > /dev/null
159 output=$(notmuch search 'subject:"testing message sent via SMTP"' | notmuch_search_sanitize)
160 test_expect_equal "$output" "thread:XXX   1974-03-29 [1/1] Notmuch Test Suite; Testing message sent via SMTP (inbox)"
161
162 test_begin_subtest "notmuch-fcc-dirs set to nil"
163 test_emacs "(setq notmuch-fcc-dirs nil)
164             (notmuch-mua-mail)
165             (princ (buffer-string))" > OUTPUT
166 cat <<EOF >EXPECTED
167 From: Notmuch Test Suite <test_suite@notmuchmail.org>
168 To: 
169 Subject: 
170 --text follows this line--
171 EOF
172 test_expect_equal_file OUTPUT EXPECTED
173
174 # Make another FCC maildir specific for the next test
175 mkdir -p mail/sent-string/cur
176 mkdir -p mail/sent-string/new
177 mkdir -p mail/sent-string/tmp
178
179 test_begin_subtest "notmuch-fcc-dirs set to a string"
180 test_emacs "(setq notmuch-fcc-dirs \"sent-string\")
181             (notmuch-mua-mail)
182             (princ (buffer-string))" > OUTPUT
183 cat <<EOF >EXPECTED
184 From: Notmuch Test Suite <test_suite@notmuchmail.org>
185 To: 
186 Subject: 
187 Fcc: ${MAIL_DIR}/sent-string
188 --text follows this line--
189 EOF
190 test_expect_equal_file OUTPUT EXPECTED
191
192 # Make more FCC maildirs specific for the next test
193 mkdir -p mail/sent-list-match/cur
194 mkdir -p mail/sent-list-match/new
195 mkdir -p mail/sent-list-match/tmp
196 mkdir -p mail/failure/cur
197 mkdir -p mail/failure/new
198 mkdir -p mail/failure/tmp
199
200 test_begin_subtest "notmuch-fcc-dirs set to a list (with match)"
201 test_emacs "(setq notmuch-fcc-dirs
202                   '((\"notmuchmail.org\" . \"sent-list-match\")
203                     (\".*\" . \"failure\")))
204             (notmuch-mua-mail)
205             (princ (buffer-string))" > OUTPUT
206 cat <<EOF >EXPECTED
207 From: Notmuch Test Suite <test_suite@notmuchmail.org>
208 To: 
209 Subject: 
210 Fcc: ${MAIL_DIR}/sent-list-match
211 --text follows this line--
212 EOF
213 test_expect_equal_file OUTPUT EXPECTED
214
215 # Make another FCC maildir specific for the next test
216 mkdir -p mail/sent-list-catch-all/cur
217 mkdir -p mail/sent-list-catch-all/new
218 mkdir -p mail/sent-list-catch-all/tmp
219  
220 test_begin_subtest "notmuch-fcc-dirs set to a list (catch-all)"
221 test_emacs "(setq notmuch-fcc-dirs
222                   '((\"example.com\" . \"failure\")
223                     (\".*\" . \"sent-list-catch-all\")))
224             (notmuch-mua-mail)
225             (princ (buffer-string))" > OUTPUT
226 cat <<EOF >EXPECTED
227 From: Notmuch Test Suite <test_suite@notmuchmail.org>
228 To: 
229 Subject: 
230 Fcc: ${MAIL_DIR}/sent-list-catch-all
231 --text follows this line--
232 EOF
233 test_expect_equal_file OUTPUT EXPECTED
234
235 test_begin_subtest "notmuch-fcc-dirs set to a list (no match)"
236 test_emacs "(setq notmuch-fcc-dirs
237                   '((\"example.com\" . \"failure\")
238                     (\"nomatchhere.net\" . \"failure\")))
239             (notmuch-mua-mail)
240             (princ (buffer-string))" > OUTPUT
241 cat <<EOF >EXPECTED
242 From: Notmuch Test Suite <test_suite@notmuchmail.org>
243 To: 
244 Subject: 
245 --text follows this line--
246 EOF
247 test_expect_equal_file OUTPUT EXPECTED
248
249 test_begin_subtest "Reply within emacs"
250 # We sed away everything before the ^From in the output to avoid getting
251 # confused by messages such as "Parsing /home/cworth/.mailrc... done"
252 test_emacs '(notmuch-search "subject:\"testing message sent via SMTP\"")
253             (notmuch-test-wait)
254             (notmuch-search-reply-to-thread)
255             (princ (buffer-string))' |
256 sed -ne '/^From/,$ p' |
257 sed -e 's/^In-Reply-To: <.*>$/In-Reply-To: <XXX>/' >OUTPUT
258 cat <<EOF >EXPECTED
259 From: Notmuch Test Suite <test_suite@notmuchmail.org>
260 To: user@example.com
261 Subject: Re: Testing message sent via SMTP
262 In-Reply-To: <XXX>
263 Fcc: $(pwd)/mail/sent
264 --text follows this line--
265 On Fri, 29 Mar 1974 10:00:00 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
266 > This is a test that messages are sent via SMTP
267 EOF
268 test_expect_equal_file OUTPUT EXPECTED
269
270 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-attachments"
271 # save as archive to test that Emacs does not re-compress .gz
272 echo ./attachment1.gz |
273 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
274             (notmuch-show-save-attachments)' > /dev/null 2>&1
275 test_expect_equal_file attachment1.gz "$EXPECTED/attachment"
276
277 test_begin_subtest "Save attachment from within emacs using notmuch-show-save-part"
278 # save as archive to test that Emacs does not re-compress .gz
279 echo ./attachment2.gz |
280 test_emacs '(notmuch-show-save-part "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com" 5)' > /dev/null 2>&1
281 test_expect_equal_file attachment2.gz "$EXPECTED/attachment"
282
283 test_begin_subtest "View raw message within emacs"
284 first_line=$(head -n1 $EXPECTED/raw-message-cf0c4d-52ad0a)
285 test_emacs '(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
286             (notmuch-show-view-raw-message)
287             (princ (buffer-string))' |
288 sed -ne "/$first_line/,\$ p" >OUTPUT
289 test_expect_equal_file OUTPUT $EXPECTED/raw-message-cf0c4d-52ad0a
290
291 test_begin_subtest "Hiding/showing signature in notmuch-show view"
292 maildir_storage_thread=$(notmuch search --output=threads id:20091117190054.GU3165@dottiness.seas.harvard.edu)
293 test_emacs "(notmuch-show \"$maildir_storage_thread\")
294             (search-forward \"Click/Enter to show.\")
295             (button-activate (button-at (point)))
296             (search-backward \"Click/Enter to hide.\")
297             (button-activate (button-at (point)))
298             (princ (buffer-string))" >OUTPUT
299 test_expect_equal_file OUTPUT $EXPECTED/notmuch-show-thread-maildir-storage
300
301 test_begin_subtest "Detection and hiding of top-post quoting of message"
302 add_message '[subject]="The problem with top-posting"' \
303             [id]=top-post-target \
304             '[body]="A: Because it messes up the order in which people normally read text.
305 Q: Why is top-posting such a bad thing?
306 A: Top-posting.
307 Q: What is the most annoying thing in e-mail?"'
308 add_message '[from]="Top Poster <top@poster.com>"' \
309             [in-reply-to]=top-post-target \
310             [references]=top-post-target \
311             '[subject]="Re: The problem with top-posting"' \
312             '[body]="Thanks for the advice! I will be sure to put it to good use.
313
314 -Top Poster
315
316 ----- Original Message -----
317 From: Notmuch Test Suite <test_suite@notmuchmail.org>
318 To: Notmuch Test Suite <test_suite@notmuchmai.org>
319 Sent: Tue, 05 Jan 2001 15:43:57 -0000
320 Subject: The problem with top-posting
321
322 Q: Why is top-posting such a bad thing?
323 A: Top-posting.
324 Q: What is the most annoying thing in e-mail?"'
325 test_emacs "(notmuch-show \"top-posting\")
326             (princ (visible-buffer-string))" >OUTPUT
327 echo "Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (inbox)
328 Subject: The problem with top-posting
329 To: Notmuch Test Suite <test_suite@notmuchmail.org>
330 Date: Tue, 05 Jan 2001 15:43:57 -0000
331
332 A: Because it messes up the order in which people normally read text.
333 Q: Why is top-posting such a bad thing?
334 A: Top-posting.
335 Q: What is the most annoying thing in e-mail?
336 Top Poster <top@poster.com> (2001-01-05) (inbox unread)
337 Subject: Re: The problem with top-posting
338 To: Notmuch Test Suite <test_suite@notmuchmail.org>
339 Date: Tue, 05 Jan 2001 15:43:57 -0000
340
341 Thanks for the advice! I will be sure to put it to good use.
342
343 -Top Poster
344
345 [ 9-line hidden original message. Click/Enter to show. ]" > EXPECTED
346 test_expect_equal_file OUTPUT EXPECTED
347
348 test_begin_subtest "Hiding message in notmuch-show view"
349 output=$(test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
350                      (notmuch-show-toggle-message)
351                      (princ (visible-buffer-string))')
352 expected=$(cat $EXPECTED/notmuch-show-thread-with-hidden-messages)
353 test_expect_equal "$output" "$expected"
354
355 test_begin_subtest "Hiding message with visible citation in notmuch-show view"
356 output=$(test_emacs '(notmuch-show "id:f35dbb950911171438k5df6eb56k77b6c0944e2e79ae@mail.gmail.com")
357                      (search-forward "Click/Enter to show.")
358                      (button-activate (button-at (point)))
359                      (notmuch-show-toggle-message)
360                      (princ (visible-buffer-string))')
361 expected=$(cat $EXPECTED/notmuch-show-thread-with-hidden-messages)
362 test_expect_equal "$output" "$expected"
363
364 test_done