2 test_description='indexing user specified headers'
3 . $(dirname "$0")/test-lib.sh || exit 1
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
8 notmuch config: Illegal argument for function
9 Cannot reopen closed or nonexistent database
11 test_expect_equal_file EXPECTED OUTPUT
15 notmuch search '*' | notmuch_search_sanitize > initial-threads
16 notmuch search --output=messages '*' > initial-message-ids
17 notmuch dump > initial-dump
19 test_begin_subtest "adding illegal prefix name, bad utf8"
20 notmuch config set index.header.$'\xFF' "List-Id" 2>&1 | sed 's/:.*$//' >OUTPUT
24 test_expect_equal_file EXPECTED OUTPUT
26 test_begin_subtest "adding illegal prefix name, reserved for notmuch"
27 notmuch config set index.header.list "List-Id" 2>OUTPUT
29 Prefix names starting with lower case letters are reserved: list
31 test_expect_equal_file EXPECTED OUTPUT
33 test_begin_subtest "adding illegal prefix name, non-word character."
34 notmuch config set index.header.l:st "List-Id" 2>OUTPUT
36 Non-word character in prefix name: l:st
38 test_expect_equal_file EXPECTED OUTPUT
40 test_begin_subtest "adding empty prefix name."
41 notmuch config set index.header. "List-Id" 2>OUTPUT
42 Non-word character in prefix name: l:st
44 Empty prefix name: index.header.
46 test_expect_equal_file EXPECTED OUTPUT
49 test_begin_subtest "adding user header"
50 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
52 test_begin_subtest "adding existing user header"
53 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
56 test_begin_subtest "retrieve user header"
57 output=$(notmuch config get index.header.List)
58 test_expect_equal "List-Id" "$output"
60 test_begin_subtest 'reindex after adding header preserves threads'
62 notmuch search '*' | notmuch_search_sanitize > OUTPUT
63 test_expect_equal_file initial-threads OUTPUT
65 test_begin_subtest "List all user headers"
66 notmuch config set index.header.Spam "X-Spam"
67 notmuch config list | grep ^index.header | notmuch_config_sanitize > OUTPUT
69 index.header.List=List-Id
70 index.header.Spam=X-Spam
72 test_expect_equal_file EXPECTED OUTPUT
74 test_begin_subtest "parse user prefix"
75 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:"notmuch"' 2>&1 | grep Tmail >OUTPUT
77 Query((Tmail AND XUList:notmuch@1))
79 test_expect_equal_file EXPECTED OUTPUT
81 test_begin_subtest "parse user prefix, stemmed"
82 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuch' 2>&1 | grep Tmail >OUTPUT
84 Query((Tmail AND ZXUList:notmuch@1))
86 test_expect_equal_file EXPECTED OUTPUT
88 test_begin_subtest "parse user prefix, phrase"
89 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuchmail.org' 2>&1 | grep Tmail >OUTPUT
91 Query((Tmail AND (XUList:notmuchmail@1 PHRASE 2 XUList:org@2)))
93 test_expect_equal_file EXPECTED OUTPUT
95 test_begin_subtest "index user header"
96 notmuch config set index.header.List "List-Id"
98 notmuch search --output=files List:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
100 MAIL_DIR/bar/baz/05:2,
101 MAIL_DIR/bar/baz/23:2,
102 MAIL_DIR/bar/baz/24:2,
103 MAIL_DIR/bar/cur/20:2,
104 MAIL_DIR/bar/new/21:2,
105 MAIL_DIR/bar/new/22:2,
106 MAIL_DIR/foo/cur/08:2,
107 MAIL_DIR/foo/new/03:2,
110 test_expect_equal_file EXPECTED OUTPUT
112 test_begin_subtest "index user header, config from file"
114 printf "\n[index]\nheader.${field_name} = List-Id\n" >> notmuch-config
116 notmuch search --output=files ${field_name}:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
118 MAIL_DIR/bar/baz/05:2,
119 MAIL_DIR/bar/baz/23:2,
120 MAIL_DIR/bar/baz/24:2,
121 MAIL_DIR/bar/cur/20:2,
122 MAIL_DIR/bar/new/21:2,
123 MAIL_DIR/bar/new/22:2,
124 MAIL_DIR/foo/cur/08:2,
125 MAIL_DIR/foo/new/03:2,
128 test_expect_equal_file EXPECTED OUTPUT