lib: setup user headers in query parser
[notmuch] / test / T750-user-header.sh
1 #!/usr/bin/env bash
2 test_description='indexing user specified headers'
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 test_begin_subtest "error adding user header before initializing DB"
6 notmuch config set index.header.List List-Id 2>&1 | notmuch_dir_sanitize > OUTPUT
7 cat <<EOF > EXPECTED
8 Error opening database at MAIL_DIR/.notmuch: No such file or directory
9 EOF
10 test_expect_equal_file EXPECTED OUTPUT
11
12 add_email_corpus
13
14 notmuch search '*' | notmuch_search_sanitize > initial-threads
15 notmuch search --output=messages '*' > initial-message-ids
16 notmuch dump > initial-dump
17
18 test_begin_subtest "adding illegal prefix name, bad utf8"
19 notmuch config set index.header.$'\xFF' "List-Id" 2>&1 | sed 's/:.*$//' >OUTPUT
20 cat <<EOF > EXPECTED
21 Invalid utf8
22 EOF
23 test_expect_equal_file EXPECTED OUTPUT
24
25 test_begin_subtest "adding illegal prefix name, reserved for notmuch"
26 notmuch config set index.header.list "List-Id" 2>OUTPUT
27 cat <<EOF > EXPECTED
28 Prefix names starting with lower case letters are reserved: list
29 EOF
30 test_expect_equal_file EXPECTED OUTPUT
31
32 test_begin_subtest "adding illegal prefix name, non-word character."
33 notmuch config set index.header.l:st "List-Id" 2>OUTPUT
34 cat <<EOF > EXPECTED
35 Non-word character in prefix name: l:st
36 EOF
37 test_expect_equal_file EXPECTED OUTPUT
38
39 test_begin_subtest "adding empty prefix name."
40 notmuch config set index.header. "List-Id" 2>OUTPUT
41 Non-word character in prefix name: l:st
42 cat <<EOF > EXPECTED
43 Empty prefix name: index.header.
44 EOF
45 test_expect_equal_file EXPECTED OUTPUT
46
47
48 test_begin_subtest "adding user header"
49 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
50
51 test_begin_subtest "adding existing user header"
52 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
53
54
55 test_begin_subtest "retrieve user header"
56 output=$(notmuch config get index.header.List)
57 test_expect_equal "List-Id" "$output"
58
59 test_begin_subtest 'reindex after adding header preserves threads'
60 notmuch reindex '*'
61 notmuch search '*' | notmuch_search_sanitize > OUTPUT
62 test_expect_equal_file initial-threads OUTPUT
63
64 test_begin_subtest "List all user headers"
65 notmuch config set index.header.Spam "X-Spam"
66 notmuch config list | grep ^index.header | notmuch_config_sanitize > OUTPUT
67 cat <<EOF > EXPECTED
68 index.header.List=List-Id
69 index.header.Spam=X-Spam
70 EOF
71 test_expect_equal_file EXPECTED OUTPUT
72
73 test_begin_subtest "parse user prefix"
74 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:"notmuch"' 2>&1 | grep Tmail >OUTPUT
75 cat <<EOF > EXPECTED
76 Query((Tmail AND XUList:notmuch@1))
77 EOF
78 test_expect_equal_file EXPECTED OUTPUT
79
80 test_begin_subtest "parse user prefix, stemmed"
81 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuch' 2>&1 | grep Tmail >OUTPUT
82 cat <<EOF > EXPECTED
83 Query((Tmail AND ZXUList:notmuch@1))
84 EOF
85 test_expect_equal_file EXPECTED OUTPUT
86
87 test_begin_subtest "parse user prefix, phrase"
88 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuchmail.org' 2>&1 | grep Tmail >OUTPUT
89 cat <<EOF > EXPECTED
90 Query((Tmail AND (XUList:notmuchmail@1 PHRASE 2 XUList:org@2)))
91 EOF
92 test_expect_equal_file EXPECTED OUTPUT
93
94 test_done