]> git.notmuchmail.org Git - notmuch/blob - test/maildir-sync
Merge tag '0.12'
[notmuch] / test / maildir-sync
1 #!/usr/bin/env 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 # Create the expected maildir structure
16 mkdir $MAIL_DIR/cur
17 mkdir $MAIL_DIR/new
18 mkdir $MAIL_DIR/tmp
19
20 test_begin_subtest "Adding 'S' flag to existing filename removes 'unread' tag"
21 add_message [subject]='"Adding S flag"' [filename]='adding-s-flag:2,' [dir]=cur
22 output=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
23 output+="
24 "
25 mv "${gen_msg_filename}" "${gen_msg_filename}S"
26 output+=$(NOTMUCH_NEW)
27 output+="
28 "
29 output+=$(notmuch search subject:"Adding S flag" | notmuch_search_sanitize)
30 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox unread)
31 No new mail. Detected 1 file rename.
32 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding S flag (inbox)"
33
34 test_begin_subtest "Adding message with 'S' flag prevents 'unread' tag"
35 add_message [subject]='"Adding message with S"' [filename]='adding-with-s-flag:2,S' [dir]=cur
36 output=$(notmuch search subject:"Adding message with S" | notmuch_search_sanitize)
37 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Adding message with S (inbox)"
38
39 test_begin_subtest "Adding 'replied' tag adds 'R' flag to filename"
40 add_message [subject]='"Adding replied tag"' [filename]='adding-replied-tag:2,S' [dir]=cur
41 notmuch tag +replied subject:"Adding replied tag"
42 output=$(cd ${MAIL_DIR}/cur; ls -1 adding-replied*)
43 test_expect_equal "$output" "adding-replied-tag:2,RS"
44
45 test_begin_subtest "notmuch show works with renamed file (without notmuch new)"
46 output=$(notmuch show --format=json id:${gen_msg_id} | filter_show_json)
47 test_expect_equal "$output" '[[[{"id": "adding-replied-tag@notmuch-test-suite",
48 "match": true,
49 "excluded": false,
50 "filename": "MAIL_DIR/cur/adding-replied-tag:2,RS",
51 "timestamp": 978709437,
52 "date_relative": "2001-01-05",
53 "tags": ["inbox","replied"],
54 "headers": {"Subject": "Adding replied tag",
55 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
56 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
57 "Date": "Fri,
58 05 Jan 2001 15:43:57 +0000"},
59 "body": [{"id": 1,
60 "content-type": "text/plain",
61 "content": "This is just a test message (#3)\n"}]},
62 []]]]'
63
64 test_expect_success 'notmuch reply works with renamed file (without notmuch new)' 'notmuch reply id:${gen_msg_id}'
65
66 test_begin_subtest "notmuch new detects no file rename after tag->flag synchronization"
67 output=$(NOTMUCH_NEW)
68 test_expect_equal "$output" "No new mail."
69
70 test_begin_subtest "When read, message moved from new to cur"
71 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
72 notmuch tag -unread subject:"Message to move to cur"
73 output=$(cd "$MAIL_DIR/cur"; ls message-to-move*)
74 test_expect_equal "$output" "message-to-move-to-cur:2,S"
75
76 test_begin_subtest "No rename should be detected by notmuch new"
77 output=$(NOTMUCH_NEW)
78 test_expect_equal "$output" "No new mail."
79 # (*) If notmuch new was not run we've got "Processed 1 file in almost
80 # no time" here. The reason is that removing unread tag in a previous
81 # test created directory document in the database but this document
82 # was not linked as subdirectory of $MAIL_DIR. Therefore notmuch new
83 # could not reach the cur/ directory and its files in it during
84 # recursive traversal.
85 #
86 # XXX: The above sounds like a bug that should be fixed. If notmuch is
87 # creating new directories in the mail store, then it should be
88 # creating all necessary database state for those directories.
89
90 test_begin_subtest "Removing 'S' flag from existing filename adds 'unread' tag"
91 add_message [subject]='"Removing S flag"' [filename]='removing-s-flag:2,S' [dir]=cur
92 output=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
93 output+="
94 "
95 mv "${gen_msg_filename}" "${gen_msg_filename%S}"
96 output+=$(NOTMUCH_NEW)
97 output+="
98 "
99 output+=$(notmuch search subject:"Removing S flag" | notmuch_search_sanitize)
100 test_expect_equal "$output" "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox)
101 No new mail. Detected 1 file rename.
102 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Removing S flag (inbox unread)"
103
104 test_begin_subtest "Removing info from filename leaves tags unchanged"
105 add_message [subject]='"Message to lose maildir info"' [filename]='message-to-lose-maildir-info' [dir]=cur
106 notmuch tag -unread subject:"Message to lose maildir info"
107 mv "$MAIL_DIR/cur/message-to-lose-maildir-info:2,S" "$MAIL_DIR/cur/message-without-maildir-info"
108 output=$(NOTMUCH_NEW)
109 output+="
110 "
111 output+=$(notmuch search subject:"Message to lose maildir info" | notmuch_search_sanitize)
112 test_expect_equal "$output" "No new mail. Detected 1 file rename.
113 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Message to lose maildir info (inbox)"
114
115 add_message [subject]='"Non-maildir message"' [dir]=notmaildir [filename]='non-maildir-message'
116 expected=$(notmuch search --output=files subject:"Non-maildir message")
117 test_expect_success "Can remove unread tag from message in non-maildir directory" 'notmuch tag -unread subject:"Non-maildir message"'
118
119 test_begin_subtest "Message in non-maildir directory does not get renamed"
120 output=$(notmuch search --output=files subject:"Non-maildir message")
121 test_expect_equal "$output" "$expected"
122
123 test_begin_subtest "notmuch dump/restore re-synchronizes maildir tags with flags"
124 # Capture current filename state
125 expected=$(ls $MAIL_DIR/cur)
126 # Add/remove some flags from filenames
127 mv $MAIL_DIR/cur/adding-replied-tag:2,RS $MAIL_DIR/cur/adding-replied-tag:2,S
128 mv $MAIL_DIR/cur/adding-s-flag:2,S $MAIL_DIR/cur/adding-s-flag:2,
129 mv $MAIL_DIR/cur/adding-with-s-flag:2,S $MAIL_DIR/cur/adding-with-s-flag:2,RS
130 mv $MAIL_DIR/cur/message-to-move-to-cur:2,S $MAIL_DIR/cur/message-to-move-to-cur:2,DS
131 notmuch dump dump.txt
132 NOTMUCH_NEW >/dev/null
133 notmuch restore dump.txt
134 output=$(ls $MAIL_DIR/cur)
135 test_expect_equal "$output" "$expected"
136
137 test_begin_subtest 'Adding flags to duplicate message tags the mail'
138 add_message [subject]='"Duplicated message"' [dir]=cur [filename]='duplicated-message:2,'
139 cp "$MAIL_DIR/cur/duplicated-message:2," "$MAIL_DIR/cur/duplicated-message-copy:2,RS"
140 NOTMUCH_NEW > output
141 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
142 test_expect_equal "$(< output)" "No new mail.
143 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
144
145 test_begin_subtest "Adding duplicate message without flags does not remove tags"
146 cp "$MAIL_DIR/cur/duplicated-message-copy:2,RS" "$MAIL_DIR/cur/duplicated-message-another-copy:2,"
147 NOTMUCH_NEW > output
148 notmuch search subject:"Duplicated message" | notmuch_search_sanitize >> output
149 test_expect_equal "$(< output)" "No new mail.
150 thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; Duplicated message (inbox replied)"
151
152 test_begin_subtest "Tag changes modify flags of multiple files"
153 notmuch tag -replied subject:"Duplicated message"
154 (cd $MAIL_DIR/cur/; ls duplicated*) > actual
155 test_expect_equal "$(< actual)"  "duplicated-message-another-copy:2,S
156 duplicated-message-copy:2,S
157 duplicated-message:2,S"
158
159 test_begin_subtest "Synchronizing tag changes preserves unsupported maildir flags"
160 add_message [subject]='"Unsupported maildir flags"' [dir]=cur [filename]='unsupported-maildir-flags:2,FSZxyz'
161 notmuch tag +unread +draft -flagged subject:"Unsupported maildir flags"
162 test_expect_equal "$(cd $MAIL_DIR/cur/; ls unsupported*)" "unsupported-maildir-flags:2,DZxyz"
163
164 test_begin_subtest "A file with non-compliant maildir info will not be renamed"
165 add_message [subject]='"Non-compliant maildir info"' [dir]=cur [filename]='non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch'
166 notmuch tag +unread +draft -flagged subject:"Non-compliant maildir info"
167 test_expect_equal "$(cd $MAIL_DIR/cur/; ls non-compliant*)" "non-compliant-maildir-info:2,These-are-not-flags-in-ASCII-order-donottouch"
168
169 test_done