#!/usr/bin/env bash

# TODO: test index-decryption-failed

test_description='indexing decrypted mail'
. ./test-lib.sh || exit 1

##################################################

add_gnupg_home
# get key fingerprint
FINGERPRINT=$($GPG --no-tty --list-secret-keys --with-colons --fingerprint | grep '^fpr:' | cut -d: -f10)

# create a test encrypted message
test_expect_success 'emacs delivery of encrypted message' \
'emacs_fcc_message \
    "test encrypted message for cleartext index 001" \
    "This is a test encrypted message with a wumpus.\n" \
    "(mml-secure-message-encrypt)"'

test_begin_subtest "search for unindexed cleartext"
output=$(notmuch search wumpus)
expected=''
test_expect_equal \
    "$output" \
    "$expected"

# create a test encrypted message that is indexed in the clear
test_expect_success 'emacs delivery of encrypted message' \
'emacs_fcc_message --try-decrypt \
    "test encrypted message for cleartext index 002" \
    "This is a test encrypted message with a wumpus.\n" \
    "(mml-secure-message-encrypt)"'

test_begin_subtest "emacs delivery of encrypted message, indexed cleartext"
output=$(notmuch search wumpus)
expected='thread:0000000000000002   2000-01-01 [1/1] Notmuch Test Suite; test encrypted message for cleartext index 002 (encrypted inbox index-decrypted)'
test_expect_equal \
    "$output" \
    "$expected"

test_done