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