imap4d: bugfixes.
* imap4d/imap4d.c (idle_timeout): Initialize to the default value. (Needed for inetd mode) * imap4d/sync.c: Revamp table handling.
Showing
2 changed files
with
25 additions
and
30 deletions
... | @@ -23,7 +23,7 @@ | ... | @@ -23,7 +23,7 @@ |
23 | #include "tcpwrap.h" | 23 | #include "tcpwrap.h" |
24 | 24 | ||
25 | mu_m_server_t server; | 25 | mu_m_server_t server; |
26 | unsigned int idle_timeout; | 26 | unsigned int idle_timeout = 1800; |
27 | int imap4d_transcript; | 27 | int imap4d_transcript; |
28 | 28 | ||
29 | mu_mailbox_t mbox; /* Current mailbox */ | 29 | mu_mailbox_t mbox; /* Current mailbox */ | ... | ... |
... | @@ -23,18 +23,27 @@ | ... | @@ -23,18 +23,27 @@ |
23 | */ | 23 | */ |
24 | static int *attr_table; | 24 | static int *attr_table; |
25 | static size_t attr_table_count; | 25 | static size_t attr_table_count; |
26 | static int attr_table_loaded; | 26 | static size_t attr_table_max; |
27 | static int attr_table_valid; | ||
27 | 28 | ||
28 | static void | 29 | static void |
29 | free_uids (void) | 30 | realloc_attributes (size_t total) |
30 | { | 31 | { |
31 | if (attr_table) | 32 | if (total > attr_table_max) |
32 | { | 33 | { |
33 | free (attr_table); | 34 | attr_table = realloc (attr_table, sizeof (*attr_table) * total); |
34 | attr_table = NULL; | 35 | if (!attr_table) |
36 | imap4d_bye (ERR_NO_MEM); | ||
37 | attr_table_max = total; | ||
35 | } | 38 | } |
39 | attr_table_count = total; | ||
40 | } | ||
41 | |||
42 | static void | ||
43 | invalidate_attr_table () | ||
44 | { | ||
45 | attr_table_valid = 0; | ||
36 | attr_table_count = 0; | 46 | attr_table_count = 0; |
37 | attr_table_loaded = 0; | ||
38 | } | 47 | } |
39 | 48 | ||
40 | static void | 49 | static void |
... | @@ -43,17 +52,8 @@ reread_attributes (void) | ... | @@ -43,17 +52,8 @@ reread_attributes (void) |
43 | size_t total = 0; | 52 | size_t total = 0; |
44 | size_t i; | 53 | size_t i; |
45 | 54 | ||
46 | free_uids (); | ||
47 | |||
48 | mu_mailbox_messages_count (mbox, &total); | 55 | mu_mailbox_messages_count (mbox, &total); |
49 | if (total > attr_table_count) | 56 | realloc_attributes (total); |
50 | { | ||
51 | attr_table = realloc (attr_table, sizeof (*attr_table) * total); | ||
52 | if (!attr_table) | ||
53 | imap4d_bye (ERR_NO_MEM); | ||
54 | attr_table_count = total; | ||
55 | } | ||
56 | |||
57 | for (i = 1; i <= total; i++) | 57 | for (i = 1; i <= total; i++) |
58 | { | 58 | { |
59 | mu_message_t msg = NULL; | 59 | mu_message_t msg = NULL; |
... | @@ -63,28 +63,27 @@ reread_attributes (void) | ... | @@ -63,28 +63,27 @@ reread_attributes (void) |
63 | mu_message_get_attribute (msg, &attr); | 63 | mu_message_get_attribute (msg, &attr); |
64 | mu_attribute_get_flags (attr, &attr_table[i-1]); | 64 | mu_attribute_get_flags (attr, &attr_table[i-1]); |
65 | } | 65 | } |
66 | attr_table_loaded = 1; | 66 | attr_table_valid = 1; |
67 | } | 67 | } |
68 | 68 | ||
69 | static void | 69 | static void |
70 | notify (void) | 70 | notify (void) |
71 | { | 71 | { |
72 | size_t total = 0; | 72 | size_t total = 0; |
73 | int reset = 0; | ||
74 | size_t recent = 0; | 73 | size_t recent = 0; |
75 | 74 | ||
76 | mu_mailbox_messages_count (mbox, &total); | 75 | mu_mailbox_messages_count (mbox, &total); |
76 | mu_mailbox_messages_recent (mbox, &recent); | ||
77 | 77 | ||
78 | if (!attr_table) | 78 | if (!attr_table_valid) |
79 | { | 79 | { |
80 | reset = 1; | ||
81 | reread_attributes (); | 80 | reread_attributes (); |
82 | mu_mailbox_messages_recent (mbox, &recent); | ||
83 | } | 81 | } |
84 | else if (attr_table) | 82 | else |
85 | { | 83 | { |
86 | size_t i; | 84 | size_t i; |
87 | 85 | ||
86 | realloc_attributes (total); | ||
88 | for (i = 1; i <= total; i++) | 87 | for (i = 1; i <= total; i++) |
89 | { | 88 | { |
90 | mu_message_t msg = NULL; | 89 | mu_message_t msg = NULL; |
... | @@ -103,14 +102,10 @@ notify (void) | ... | @@ -103,14 +102,10 @@ notify (void) |
103 | attr_table[i-1] = nflags; | 102 | attr_table[i-1] = nflags; |
104 | } | 103 | } |
105 | } | 104 | } |
106 | mu_mailbox_messages_recent (mbox, &recent); | ||
107 | } | 105 | } |
108 | 106 | ||
109 | io_untagged_response (RESP_NONE, "%lu EXISTS", (unsigned long) total); | 107 | io_untagged_response (RESP_NONE, "%lu EXISTS", (unsigned long) total); |
110 | io_untagged_response (RESP_NONE, "%lu RECENT", (unsigned long) recent); | 108 | io_untagged_response (RESP_NONE, "%lu RECENT", (unsigned long) recent); |
111 | |||
112 | if (!reset) | ||
113 | reread_attributes (); | ||
114 | } | 109 | } |
115 | 110 | ||
116 | size_t | 111 | size_t |
... | @@ -190,8 +185,8 @@ imap4d_sync (void) | ... | @@ -190,8 +185,8 @@ imap4d_sync (void) |
190 | It may be because of close or before select/examine a new mailbox. | 185 | It may be because of close or before select/examine a new mailbox. |
191 | If it was a close we do not send any notification. */ | 186 | If it was a close we do not send any notification. */ |
192 | if (mbox == NULL) | 187 | if (mbox == NULL) |
193 | free_uids (); | 188 | invalidate_attr_table (); |
194 | else if (!attr_table_loaded || !mu_mailbox_is_updated (mbox)) | 189 | else if (!attr_table_valid || !mu_mailbox_is_updated (mbox)) |
195 | { | 190 | { |
196 | if (mailbox_corrupt) | 191 | if (mailbox_corrupt) |
197 | { | 192 | { |
... | @@ -204,7 +199,7 @@ imap4d_sync (void) | ... | @@ -204,7 +199,7 @@ imap4d_sync (void) |
204 | if (status) | 199 | if (status) |
205 | imap4d_bye (ERR_MAILBOX_CORRUPTED); | 200 | imap4d_bye (ERR_MAILBOX_CORRUPTED); |
206 | imap4d_set_observer (mbox); | 201 | imap4d_set_observer (mbox); |
207 | free_uids (); | 202 | invalidate_attr_table (); |
208 | mailbox_corrupt = 0; | 203 | mailbox_corrupt = 0; |
209 | io_untagged_response (RESP_NONE, | 204 | io_untagged_response (RESP_NONE, |
210 | "OK [ALERT] Mailbox modified by another program"); | 205 | "OK [ALERT] Mailbox modified by another program"); | ... | ... |
-
Please register or sign in to post a comment