]> git.notmuchmail.org Git - notmuch/blob - test/maildir-sync
test: Rework testing of maildir-synchronization feature.
[notmuch] / test / maildir-sync
1 #!/bin/bash
2
3 test_description="maildir synchronization"
4
5 . ./test-lib.sh
6
7 # Much easier to examine differences if the "notmuch show
8 # --format=json" output includes some newlines. Also, need to avoid
9 # including the local value of MAIL_DIR in the result.
10 filter_show_json() {
11     sed -e 's/, /,\n/g'  | sed -e "s|${MAIL_DIR}/|MAIL_DIR/|"
12     echo
13 }
14
15 cat >> "$NOTMUCH_CONFIG" <<EOF
16 [maildir]
17 synchronize_flags=true
18 EOF
19
20 # Create the expected maildir structure
21 mkdir $MAIL_DIR/cur
22 mkdir $MAIL_DIR/new
23 mkdir $MAIL_DIR/tmp
24
25 test_begin_subtest "Adding 'S' flag to existing filename removes 'unread' tag"
26 add_message [subject]='"Adding S flag"' [filename]='adding-s-flag:2,' [dir]=cur
27 output=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
28 output+="
29 "
30 mv "${gen_msg_filename}" "${gen_msg_filename}S"
31 increment_mtime "$(dirname "${gen_msg_filename}")"
32 output+=$(NOTMUCH_NEW)
33 output+="
34 "
35 output+=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
36 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox unread)
37 No new mail. Detected 1 file rename.
38 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox)"
39
40 test_begin_subtest "Adding message with 'S' flag prevents 'unread' tag"
41 add_message [subject]='"Adding message with S"' [filename]='adding-with-s-flag:2,S' [dir]=cur
42 output=$(notmuch search subject:"Adding message with S" | notmuch_search_sanitize)
43 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding message with S (inbox)"
44
45 test_begin_subtest "Adding 'replied' tag adds 'R' flag to filename"
46 add_message [subject]='"Adding replied tag"' [filename]='adding-replied-tag:2,S' [dir]=cur
47 notmuch tag +replied subject:"Adding replied tag"
48 output=$(cd ${MAIL_DIR}/cur; ls -1 adding-replied*)
49 test_expect_equal "$output" "adding-replied-tag:2,RS"
50
51 test_begin_subtest "notmuch show works with renamed file (without notmuch new)"
52 output=$(notmuch show --format=json id:${gen_msg_id} | filter_show_json)
53 test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
54 "match": true,
55 "filename": "MAIL_DIR/cur/adding-replied-tag:2,RS",
56 "timestamp": 978709437,
57 "date_relative": "2001-01-05",
58 "tags": ["inbox","replied"],
59 "headers": {"Subject": "Adding replied tag",
60 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
61 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
62 "Cc": "",
63 "Bcc": "",
64 "Date": "Tue,
65 05 Jan 2001 15:43:57 -0000"},
66 "body": [{"id": 1,
67 "content-type": "text/plain",
68 "content": "This is just a test message (#3)\n"}]},
69 []]]]'
70
71 test_expect_success 'notmuch reply works with renamed file (without notmuch new)' 'notmuch reply id:${gen_msg_id}'
72
73 test_begin_subtest "notmuch new detects no file rename after tag->flag synchronization"
74 increment_mtime "$(dirname ${gen_msg_filename})"
75 output=$(NOTMUCH_NEW)
76 test_expect_equal "$output" "No new mail."
77
78 test_begin_subtest "When read, message moved from new to cur"
79 add_message [subject]='"Message to move to cur"' [date]='"Sat, 01 Jan 2000 12:00:00 -0000"' [filename]='message-to-move-to-cur' [dir]=new
80 notmuch tag -unread subject:"Message to move to cur"
81 output=$(cd "$MAIL_DIR/cur"; ls message-to-move*)
82 test_expect_equal "$output" "message-to-move-to-cur:2,S"
83
84 test_begin_subtest "No rename should be detected by notmuch new"
85 increment_mtime "$MAIL_DIR/cur"
86 output=$(NOTMUCH_NEW)
87 test_expect_equal "$output" "No new mail."
88 # (*) If notmuch new was not run we've got "Processed 1 file in almost
89 # no time" here. The reason is that removing unread tag in a previous
90 # test created directory document in the database but this document
91 # was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new
92 # could not reach the cur/ directory and its files in it during
93 # recurive traversal.
94 #
95 # XXX: The above sounds like a bug that should be fixed. If notmuch is
96 # creating new directories in the mail store, then it should be
97 # creating all necessary database state for those directories.
98
99 test_begin_subtest "Removing info from filename leaves tags unchanged"
100 add_message [subject]='"Message to lose maildir info"' [filename]='message-to-lose-maildir-info' [dir]=cur
101 notmuch tag -unread subject:"Message to lose maildir info"
102 mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,S" "$MAIL_DIR/cur/message-without-maildir-info"
103 increment_mtime "$MAIL_DIR/cur"
104 output=$(NOTMUCH_NEW)
105 output+="
106 "
107 output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search_sanitize)
108 test_expect_equal "$output" "No new mail. Detected 1 file rename.
109 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)"
110
111 add_message [subject]='"Non-maildir message"' [dir]=notmaildir/new [filename]='non-maildir-message'
112 expected=$(notmuch search --output=files subject:"Non-maildir message")
113 test_expect_success "Can remove unread tag from message in non-maildir directory" 'notmuch tag -unread subject:"Non-maildir message"'
114
115 test_begin_subtest "Message in non-maildir directory does not get renamed"
116 output=$(notmuch search --output=files subject:"Non-maildir message")
117 test_expect_equal "$output" "$expected"
118
119 test_begin_subtest "notmuch dump/restore re-synchronizes maildir tags with flags"
120 # Capture current filename state
121 expected=$(ls $MAIL_DIR/cur)
122 # Add/remove some flags from filenames
123 mv $MAIL_DIR/cur/adding-replied-tag:2,RS $MAIL_DIR/cur/adding-replied-tag:2,S
124 mv $MAIL_DIR/cur/adding-s-flag:2,S $MAIL_DIR/cur/adding-s-flag:2,
125 mv $MAIL_DIR/cur/adding-with-s-flag:2,S $MAIL_DIR/cur/adding-with-s-flag:2,RS
126 mv $MAIL_DIR/cur/message-to-move-to-cur:2,S $MAIL_DIR/cur/message-to-move-to-cur:2,SD
127 increment_mtime $MAIL_DIR/cur
128 notmuch dump dump.txt
129 NOTMUCH_NEW >/dev/null
130 notmuch restore dump.txt
131 output=$(ls $MAIL_DIR/cur)
132 test_expect_equal "$output" "$expected"
133
134 test_done