]> git.notmuchmail.org Git - notmuch/blob - test/T750-user-header.sh
CLI/config: use notmuch_database_reopen
[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 notmuch config: Illegal argument for function
9 Cannot reopen closed or nonexistent database
10 EOF
11 test_expect_equal_file EXPECTED OUTPUT
12
13 add_email_corpus
14
15 notmuch search '*' | notmuch_search_sanitize > initial-threads
16 notmuch search --output=messages '*' > initial-message-ids
17 notmuch dump > initial-dump
18
19 test_begin_subtest "adding illegal prefix name, bad utf8"
20 notmuch config set index.header.$'\xFF' "List-Id" 2>&1 | sed 's/:.*$//' >OUTPUT
21 cat <<EOF > EXPECTED
22 Invalid utf8
23 EOF
24 test_expect_equal_file EXPECTED OUTPUT
25
26 test_begin_subtest "adding illegal prefix name, reserved for notmuch"
27 notmuch config set index.header.list "List-Id" 2>OUTPUT
28 cat <<EOF > EXPECTED
29 Prefix names starting with lower case letters are reserved: list
30 EOF
31 test_expect_equal_file EXPECTED OUTPUT
32
33 test_begin_subtest "adding illegal prefix name, non-word character."
34 notmuch config set index.header.l:st "List-Id" 2>OUTPUT
35 cat <<EOF > EXPECTED
36 Non-word character in prefix name: l:st
37 EOF
38 test_expect_equal_file EXPECTED OUTPUT
39
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
43 cat <<EOF > EXPECTED
44 Empty prefix name: index.header.
45 EOF
46 test_expect_equal_file EXPECTED OUTPUT
47
48
49 test_begin_subtest "adding user header"
50 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
51
52 test_begin_subtest "adding existing user header"
53 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
54
55
56 test_begin_subtest "retrieve user header"
57 output=$(notmuch config get index.header.List)
58 test_expect_equal "List-Id" "$output"
59
60 test_begin_subtest 'reindex after adding header preserves threads'
61 notmuch reindex '*'
62 notmuch search '*' | notmuch_search_sanitize > OUTPUT
63 test_expect_equal_file initial-threads OUTPUT
64
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
68 cat <<EOF > EXPECTED
69 index.header.List=List-Id
70 index.header.Spam=X-Spam
71 EOF
72 test_expect_equal_file EXPECTED OUTPUT
73
74 test_begin_subtest "parse user prefix"
75 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:"notmuch"' 2>&1 | grep Tmail >OUTPUT
76 cat <<EOF > EXPECTED
77 Query((Tmail AND XUList:notmuch@1))
78 EOF
79 test_expect_equal_file EXPECTED OUTPUT
80
81 test_begin_subtest "parse user prefix, stemmed"
82 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuch' 2>&1 | grep Tmail >OUTPUT
83 cat <<EOF > EXPECTED
84 Query((Tmail AND ZXUList:notmuch@1))
85 EOF
86 test_expect_equal_file EXPECTED OUTPUT
87
88 test_begin_subtest "parse user prefix, phrase"
89 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuchmail.org' 2>&1 | grep Tmail >OUTPUT
90 cat <<EOF > EXPECTED
91 Query((Tmail AND (XUList:notmuchmail@1 PHRASE 2 XUList:org@2)))
92 EOF
93 test_expect_equal_file EXPECTED OUTPUT
94
95 test_begin_subtest "index user header"
96 notmuch config set index.header.List "List-Id"
97 notmuch reindex '*'
98 notmuch search --output=files List:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
99 cat <<EOF > EXPECTED
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,
108 MAIL_DIR/new/04:2,
109 EOF
110 test_expect_equal_file EXPECTED OUTPUT
111
112 test_begin_subtest "index user header, config from file"
113 field_name="Test"
114 printf "\n[index]\nheader.${field_name} = List-Id\n" >> notmuch-config
115 notmuch reindex '*'
116 notmuch search --output=files ${field_name}:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
117 cat <<EOF > EXPECTED
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,
126 MAIL_DIR/new/04:2,
127 EOF
128 test_expect_equal_file EXPECTED OUTPUT
129
130 test_done