(notify_deleted): Implemented "immediate decrement
rule" required by RFC2060 Interchanged reset_uid() and notify(). Notify decides whether and when reset_uid must be called. (notify): Call reset_uid(). when necessary. (reset_uid): Do not call notify(). (imap4d_sync): Call notify().
Showing
1 changed file
with
39 additions
and
8 deletions
... | @@ -53,7 +53,7 @@ notify_flag (size_t msgno, attribute_t oattr) | ... | @@ -53,7 +53,7 @@ notify_flag (size_t msgno, attribute_t oattr) |
53 | mailbox_get_message (mbox, msgno, &msg); | 53 | mailbox_get_message (mbox, msgno, &msg); |
54 | message_get_attribute (msg, &nattr); | 54 | message_get_attribute (msg, &nattr); |
55 | status = attribute_is_equal (oattr, nattr); | 55 | status = attribute_is_equal (oattr, nattr); |
56 | //if (!attribute_is_equal (oattr, nattr)) | 56 | |
57 | if (status == 0) | 57 | if (status == 0) |
58 | { | 58 | { |
59 | char *abuf = malloc (1);; | 59 | char *abuf = malloc (1);; |
... | @@ -103,18 +103,26 @@ notify_flag (size_t msgno, attribute_t oattr) | ... | @@ -103,18 +103,26 @@ notify_flag (size_t msgno, attribute_t oattr) |
103 | } | 103 | } |
104 | } | 104 | } |
105 | 105 | ||
106 | /* The EXPUNGE response reports that the specified message sequence | ||
107 | number has been permanently removed from the mailbox. The message | ||
108 | sequence number for each successive message in the mailbox is | ||
109 | immediately decremented by 1, and this decrement is reflected in | ||
110 | message sequence numbers in subsequent responses (including other | ||
111 | untagged EXPUNGE responses). */ | ||
106 | static void | 112 | static void |
107 | notify_deleted (void) | 113 | notify_deleted (void) |
108 | { | 114 | { |
109 | if (uid_table) | 115 | if (uid_table) |
110 | { | 116 | { |
111 | size_t i; | 117 | size_t i; |
118 | size_t decr = 0; | ||
112 | for (i = 0; i < uid_table_count; i++) | 119 | for (i = 0; i < uid_table_count; i++) |
113 | { | 120 | { |
114 | if (!(uid_table[i].notify)) | 121 | if (!(uid_table[i].notify)) |
115 | { | 122 | { |
116 | util_out (RESP_NONE, "%d EXPUNGED", uid_table[i].msgno); | 123 | util_out (RESP_NONE, "%d EXPUNGED", uid_table[i].msgno-decr); |
117 | uid_table[i].notify = 1; | 124 | uid_table[i].notify = 1; |
125 | decr++; | ||
118 | } | 126 | } |
119 | } | 127 | } |
120 | } | 128 | } |
... | @@ -143,12 +151,22 @@ notify_uid (size_t uid) | ... | @@ -143,12 +151,22 @@ notify_uid (size_t uid) |
143 | static void | 151 | static void |
144 | notify (void) | 152 | notify (void) |
145 | { | 153 | { |
154 | size_t total = 0; | ||
155 | int reset = 0; | ||
156 | |||
157 | mailbox_messages_count (mbox, &total); | ||
158 | |||
159 | if (!uid_table) | ||
160 | { | ||
161 | reset = 1; | ||
162 | reset_uids (); | ||
163 | } | ||
164 | |||
146 | if (uid_table) | 165 | if (uid_table) |
147 | { | 166 | { |
148 | size_t total = 0; | ||
149 | size_t i; | 167 | size_t i; |
150 | size_t recent = 0; | 168 | size_t recent = 0; |
151 | mailbox_messages_count (mbox, &total); | 169 | |
152 | for (i = 1; i <= total; i++) | 170 | for (i = 1; i <= total; i++) |
153 | { | 171 | { |
154 | message_t msg = NULL; | 172 | message_t msg = NULL; |
... | @@ -158,11 +176,16 @@ notify (void) | ... | @@ -158,11 +176,16 @@ notify (void) |
158 | if (!notify_uid (uid)) | 176 | if (!notify_uid (uid)) |
159 | recent++; | 177 | recent++; |
160 | } | 178 | } |
179 | notify_deleted (); | ||
161 | util_out (RESP_NONE, "%d EXISTS", total); | 180 | util_out (RESP_NONE, "%d EXISTS", total); |
162 | if (recent) | 181 | if (recent) |
163 | util_out (RESP_NONE, "%d RECENT", recent); | 182 | util_out (RESP_NONE, "%d RECENT", recent); |
164 | notify_deleted (); | ||
165 | } | 183 | } |
184 | |||
185 | if (!reset) | ||
186 | reset_uids (); | ||
187 | else | ||
188 | reset_notify (); | ||
166 | } | 189 | } |
167 | 190 | ||
168 | static void | 191 | static void |
... | @@ -180,12 +203,20 @@ free_uids (void) | ... | @@ -180,12 +203,20 @@ free_uids (void) |
180 | } | 203 | } |
181 | 204 | ||
182 | static void | 205 | static void |
206 | reset_notify (void) | ||
207 | { | ||
208 | size_t i; | ||
209 | |||
210 | for (i = 0; i < uid_table_count; i++) | ||
211 | uid_table[i].notify = 0; | ||
212 | } | ||
213 | |||
214 | static void | ||
183 | reset_uids (void) | 215 | reset_uids (void) |
184 | { | 216 | { |
185 | size_t total = 0; | 217 | size_t total = 0; |
186 | size_t i; | 218 | size_t i; |
187 | 219 | ||
188 | notify (); | ||
189 | free_uids (); | 220 | free_uids (); |
190 | 221 | ||
191 | mailbox_messages_count (mbox, &total); | 222 | mailbox_messages_count (mbox, &total); |
... | @@ -246,13 +277,13 @@ imap4d_sync (void) | ... | @@ -246,13 +277,13 @@ imap4d_sync (void) |
246 | if (mbox == NULL) | 277 | if (mbox == NULL) |
247 | free_uids (); | 278 | free_uids (); |
248 | else if (uid_table == NULL || !mailbox_is_updated (mbox)) | 279 | else if (uid_table == NULL || !mailbox_is_updated (mbox)) |
249 | reset_uids (); | 280 | notify (); |
250 | else | 281 | else |
251 | { | 282 | { |
252 | size_t count = 0; | 283 | size_t count = 0; |
253 | mailbox_messages_count (mbox, &count); | 284 | mailbox_messages_count (mbox, &count); |
254 | if (count != uid_table_count) | 285 | if (count != uid_table_count) |
255 | reset_uids (); | 286 | notify (); |
256 | } | 287 | } |
257 | return 0; | 288 | return 0; |
258 | } | 289 | } | ... | ... |
-
Please register or sign in to post a comment