2 test_description='index attachments as text'
3 . $(dirname "$0")/test-lib.sh || exit 1
5 add_email_corpus indexing
6 test_begin_subtest "empty as_text; skip text/x-diff"
7 messages=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain)
8 count=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz)
9 test_expect_equal "$messages,$count" "1,0"
11 notmuch config set index.as_text "^text/"
12 add_email_corpus indexing
14 test_begin_subtest "as_index is text/; find text/x-diff"
15 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
16 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
17 test_expect_equal_file_nonempty EXPECTED OUTPUT
19 test_begin_subtest "reindex with empty as_text, skips text/x-diff"
20 notmuch config set index.as_text
22 messages=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain)
23 count=$(notmuch count id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz)
24 test_expect_equal "$messages,$count" "1,0"
26 test_begin_subtest "reindex with empty as_text; skips application/pdf"
27 notmuch config set index.as_text
29 gmessages=$(notmuch count id:871qo9p4tf.fsf@tethera.net)
30 count=$(notmuch count id:871qo9p4tf.fsf@tethera.net and body:not-really-PDF)
31 test_expect_equal "$messages,$count" "1,0"
33 test_begin_subtest "reindex with as_text as text/; finds text/x-diff"
34 notmuch config set index.as_text "^text/"
36 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
37 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
38 test_expect_equal_file_nonempty EXPECTED OUTPUT
40 test_begin_subtest "reindex with as_text as text/; skips application/pdf"
41 notmuch config set index.as_text "^text/"
42 notmuch config set index.as_text
44 messages=$(notmuch count id:871qo9p4tf.fsf@tethera.net)
45 count=$(notmuch count id:871qo9p4tf.fsf@tethera.net and body:not-really-PDF)
46 test_expect_equal "$messages,$count" "1,0"
48 test_begin_subtest "as_text has multiple regexes"
49 notmuch config set index.as_text "blahblah;^text/"
51 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
52 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
53 test_expect_equal_file_nonempty EXPECTED OUTPUT
55 test_begin_subtest "as_text is non-anchored regex"
56 notmuch config set index.as_text "e.t/"
58 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain > EXPECTED
59 notmuch search id:20200930101213.2m2pt3jrspvcrxfx@localhost.localdomain and ersatz > OUTPUT
60 test_expect_equal_file_nonempty EXPECTED OUTPUT
62 test_begin_subtest "as_text is 'application/pdf'"
63 notmuch config set index.as_text "^application/pdf$"
65 notmuch search id:871qo9p4tf.fsf@tethera.net > EXPECTED
66 notmuch search id:871qo9p4tf.fsf@tethera.net and '"not really PDF"' > OUTPUT
67 test_expect_equal_file_nonempty EXPECTED OUTPUT
69 test_begin_subtest "as_text is bad regex"
70 notmuch config set index.as_text '['
71 notmuch reindex '*' >& OUTPUT
73 Error in index.as_text: Invalid regular expression: [
75 test_expect_equal_file EXPECTED OUTPUT