]> git.notmuchmail.org Git - notmuch/blob - test/T750-user-header.sh
b97b00b6ce47fdced664119f99c6c30ac90fe88f
[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_done