]> git.cworth.org Git - notmuch/blob - test/T750-user-header.sh
emacs: honour notmuch-show-text/html-blocked-images in w3m messages
[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 add_email_corpus
6
7 notmuch search '*' 2>1 | notmuch_search_sanitize > initial-threads
8 notmuch search --output=messages '*' 2>/dev/null > initial-message-ids
9 notmuch dump > initial-dump
10
11 test_begin_subtest "adding illegal prefix name, bad utf8"
12 notmuch config set index.header.$'\xFF' "List-Id" 2>&1 | sed 's/:.*$//' >OUTPUT
13 cat <<EOF > EXPECTED
14 Invalid utf8
15 EOF
16 test_expect_equal_file EXPECTED OUTPUT
17
18 test_begin_subtest "adding illegal prefix name, reserved for notmuch"
19 notmuch config set index.header.list "List-Id" 2>OUTPUT
20 cat <<EOF > EXPECTED
21 Prefix names starting with lower case letters are reserved: list
22 EOF
23 test_expect_equal_file EXPECTED OUTPUT
24
25 test_begin_subtest "adding illegal prefix name, non-word character."
26 notmuch config set index.header.l:st "List-Id" 2>OUTPUT
27 cat <<EOF > EXPECTED
28 Non-word character in prefix name: l:st
29 EOF
30 test_expect_equal_file EXPECTED OUTPUT
31
32 test_begin_subtest "adding empty prefix name."
33 notmuch config set index.header. "List-Id" 2>OUTPUT
34 Non-word character in prefix name: l:st
35 cat <<EOF > EXPECTED
36 Empty prefix name: index.header.
37 EOF
38 test_expect_equal_file EXPECTED OUTPUT
39
40
41 test_begin_subtest "adding user header"
42 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
43
44 test_begin_subtest "adding existing user header"
45 test_expect_code 0 "notmuch config set index.header.List \"List-Id\""
46
47
48 test_begin_subtest "retrieve user header"
49 output=$(notmuch config get index.header.List)
50 test_expect_equal "List-Id" "$output"
51
52 test_begin_subtest 'reindex after adding header preserves threads'
53 notmuch reindex '*'
54 notmuch search '*' | notmuch_search_sanitize > OUTPUT
55 test_expect_equal_file initial-threads OUTPUT
56
57 test_begin_subtest "List all user headers"
58 notmuch config set index.header.Spam "X-Spam"
59 notmuch config list | grep ^index.header | notmuch_config_sanitize > OUTPUT
60 cat <<EOF > EXPECTED
61 index.header.List=List-Id
62 index.header.Spam=X-Spam
63 EOF
64 test_expect_equal_file EXPECTED OUTPUT
65
66 test_begin_subtest "parse user prefix"
67 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:"notmuch"' 2>&1 | grep Tmail >OUTPUT
68 cat <<EOF > EXPECTED
69 Query((Tmail AND XUList:notmuch@1))
70 EOF
71 test_expect_equal_file EXPECTED OUTPUT
72
73 test_begin_subtest "parse user prefix, stemmed"
74 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuch' 2>&1 | grep Tmail >OUTPUT
75 cat <<EOF > EXPECTED
76 Query((Tmail AND ZXUList:notmuch@1))
77 EOF
78 test_expect_equal_file EXPECTED OUTPUT
79
80 test_begin_subtest "parse user prefix, phrase"
81 NOTMUCH_DEBUG_QUERY=t notmuch count 'List:notmuchmail.org' 2>&1 | grep Tmail >OUTPUT
82 cat <<EOF > EXPECTED
83 Query((Tmail AND (XUList:notmuchmail@1 PHRASE 2 XUList:org@2)))
84 EOF
85 test_expect_equal_file EXPECTED OUTPUT
86
87 test_begin_subtest "index user header"
88 notmuch config set index.header.List "List-Id"
89 notmuch reindex '*'
90 notmuch search --output=files List:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
91 cat <<EOF > EXPECTED
92 MAIL_DIR/bar/baz/05:2,
93 MAIL_DIR/bar/baz/23:2,
94 MAIL_DIR/bar/baz/24:2,
95 MAIL_DIR/bar/cur/20:2,
96 MAIL_DIR/bar/new/21:2,
97 MAIL_DIR/bar/new/22:2,
98 MAIL_DIR/foo/cur/08:2,
99 MAIL_DIR/foo/new/03:2,
100 MAIL_DIR/new/04:2,
101 EOF
102 test_expect_equal_file EXPECTED OUTPUT
103
104 test_begin_subtest "index user header, config from file"
105 field_name="Test"
106 printf "\n[index]\nheader.${field_name} = List-Id\n" >> notmuch-config
107 notmuch reindex '*'
108 notmuch search --output=files ${field_name}:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
109 cat <<EOF > EXPECTED
110 MAIL_DIR/bar/baz/05:2,
111 MAIL_DIR/bar/baz/23:2,
112 MAIL_DIR/bar/baz/24:2,
113 MAIL_DIR/bar/cur/20:2,
114 MAIL_DIR/bar/new/21:2,
115 MAIL_DIR/bar/new/22:2,
116 MAIL_DIR/foo/cur/08:2,
117 MAIL_DIR/foo/new/03:2,
118 MAIL_DIR/new/04:2,
119 EOF
120 test_expect_equal_file EXPECTED OUTPUT
121
122 test_done