]> git.cworth.org Git - notmuch/blob - test/T630-emacs-draft.sh
NEWS: The minimum supported major version of Emacs is now 24.
[notmuch] / test / T630-emacs-draft.sh
1 #!/usr/bin/env bash
2 test_description="Emacs Draft Handling"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_email_corpus
6
7 notmuch config set search.exclude_tags deleted
8
9 test_begin_subtest "Saving a draft indexes it"
10 test_emacs '(notmuch-mua-mail)
11             (message-goto-subject)
12             (insert "draft-test-0001")
13             (notmuch-draft-save)
14             (test-output)'
15 count1=$(notmuch count tag:draft)
16 count2=$(notmuch count subject:draft-test-0001)
17 test_expect_equal "$count1=$count2" "1=1"
18
19 test_begin_subtest "Saving a draft tags previous draft as deleted"
20 test_emacs '(notmuch-mua-mail)
21             (message-goto-subject)
22             (insert "draft-test-0002")
23             (notmuch-draft-save)
24             (notmuch-draft-save)
25             (test-output)'
26 count1=$(notmuch count tag:draft)
27 count2=$(notmuch count subject:draft-test-0002)
28
29 test_expect_equal "$count1,$count2" "2,1"
30
31 test_begin_subtest "Saving a signed draft adds header"
32 test_emacs '(notmuch-mua-mail)
33             (message-goto-subject)
34             (insert "draft-test-0003")
35             ;; We would use (mml-secure-message-sign) but on emacs23
36             ;; that only signs the part, not the whole message.
37             (mml-secure-message mml-secure-method '\''sign)
38             (notmuch-draft-save)
39             (test-output)'
40 header_count=$(notmuch show --format=raw subject:draft-test-0003 | grep -c ^X-Notmuch-Emacs-Secure)
41 body_count=$(notmuch notmuch show --format=raw subject:draft-test-0003 | grep -c '^\<#secure')
42 test_expect_equal "$header_count,$body_count" "1,0"
43
44 test_begin_subtest "Refusing to save an encrypted draft"
45 test_emacs '(notmuch-mua-mail)
46             (message-goto-subject)
47             (insert "draft-test-0004")
48             (mml-secure-message-sign-encrypt)
49             (let ((notmuch-draft-save-plaintext nil))
50                      (notmuch-draft-save))
51             (test-output)'
52 count1=$(notmuch count tag:draft)
53 count2=$(notmuch count subject:draft-test-0004)
54
55 test_expect_equal "$count1,$count2" "3,0"
56
57 test_begin_subtest "Resuming a signed draft"
58
59 test_emacs '(notmuch-show "subject:draft-test-0003")
60             (notmuch-show-resume-message)
61             (test-output)'
62 notmuch_dir_sanitize OUTPUT > OUTPUT.clean
63 cat <<EOF | notmuch_dir_sanitize >EXPECTED
64 From: Notmuch Test Suite <test_suite@notmuchmail.org>
65 To: 
66 Subject: draft-test-0003
67 Fcc: MAIL_DIR/sent
68 --text follows this line--
69 <#secure method=pgpmime mode=sign>
70 EOF
71 test_expect_equal_file EXPECTED OUTPUT.clean
72 test_done