1#!/usr/bin/env bash 2test_description="Emacs Draft Handling" 3. $(dirname "$0")/test-lib.sh || exit 1 4. $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1 5 6test_require_emacs 7add_email_corpus 8 9notmuch config set search.exclude_tags deleted 10 11test_begin_subtest "Saving a draft indexes it" 12test_emacs '(notmuch-mua-mail) 13 (message-goto-subject) 14 (insert "draft-test-0001") 15 (notmuch-draft-save) 16 (test-output)' 17count1=$(notmuch count tag:draft) 18count2=$(notmuch count subject:draft-test-0001) 19test_expect_equal "$count1=$count2" "1=1" 20 21test_begin_subtest "Saving a draft tags previous draft as deleted" 22test_emacs '(notmuch-mua-mail) 23 (message-goto-subject) 24 (insert "draft-test-0002") 25 (notmuch-draft-save) 26 (notmuch-draft-save) 27 (test-output)' 28count1=$(notmuch count tag:draft) 29count2=$(notmuch count subject:draft-test-0002) 30 31test_expect_equal "$count1,$count2" "2,1" 32 33test_begin_subtest "Saving a signed draft adds header" 34test_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)' 42header_count=$(notmuch show --format=raw subject:draft-test-0003 | grep -c ^X-Notmuch-Emacs-Secure) 43body_count=$(notmuch notmuch show --format=raw subject:draft-test-0003 | grep -c '^\<#secure') 44test_expect_equal "$header_count,$body_count" "1,0" 45 46test_begin_subtest "Refusing to save an encrypted draft" 47test_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)' 54count1=$(notmuch count tag:draft) 55count2=$(notmuch count subject:draft-test-0004) 56 57test_expect_equal "$count1,$count2" "3,0" 58 59test_begin_subtest "Resuming a signed draft" 60 61test_emacs '(notmuch-show "subject:draft-test-0003") 62 (notmuch-show-resume-message) 63 (test-output)' 64notmuch_dir_sanitize OUTPUT > OUTPUT.clean 65cat <<EOF | notmuch_dir_sanitize >EXPECTED 66From: Notmuch Test Suite <test_suite@notmuchmail.org> 67To: 68Subject: draft-test-0003 69Fcc: MAIL_DIR/sent 70--text follows this line-- 71<#secure method=pgpmime mode=sign> 72EOF 73test_expect_equal_file EXPECTED OUTPUT.clean 74test_done 75