(deliver_pending_bulletins): Return immediately, if unable to count messages in the bulletin box
Showing
1 changed file
with
43 additions
and
38 deletions
... | @@ -150,8 +150,8 @@ read_bulletin_db (size_t *pnum) | ... | @@ -150,8 +150,8 @@ read_bulletin_db (size_t *pnum) |
150 | mu_strerror (errno)); | 150 | mu_strerror (errno)); |
151 | return 1; | 151 | return 1; |
152 | } | 152 | } |
153 | 153 | ||
154 | s = MU_DATUM_SIZE(data); | 154 | s = MU_DATUM_SIZE (data); |
155 | if (s < sizeof sbuf) | 155 | if (s < sizeof sbuf) |
156 | bufptr = sbuf; | 156 | bufptr = sbuf; |
157 | else | 157 | else |
... | @@ -165,7 +165,7 @@ read_bulletin_db (size_t *pnum) | ... | @@ -165,7 +165,7 @@ read_bulletin_db (size_t *pnum) |
165 | bufptr = buf; | 165 | bufptr = buf; |
166 | } | 166 | } |
167 | 167 | ||
168 | memcpy (bufptr, MU_DATUM_PTR(data), s); | 168 | memcpy (bufptr, MU_DATUM_PTR (data), s); |
169 | bufptr[s] = 0; | 169 | bufptr[s] = 0; |
170 | mu_dbm_datum_free(&data); | 170 | mu_dbm_datum_free(&data); |
171 | 171 | ||
... | @@ -180,7 +180,7 @@ read_bulletin_db (size_t *pnum) | ... | @@ -180,7 +180,7 @@ read_bulletin_db (size_t *pnum) |
180 | { | 180 | { |
181 | long n; | 181 | long n; |
182 | 182 | ||
183 | n = *(long*)MU_DATUM_PTR(data); | 183 | n = *(long*)MU_DATUM_PTR (data); |
184 | if (n >= 0) | 184 | if (n >= 0) |
185 | { | 185 | { |
186 | syslog (LOG_INFO, | 186 | syslog (LOG_INFO, |
... | @@ -220,11 +220,11 @@ write_bulletin_db (size_t num) | ... | @@ -220,11 +220,11 @@ write_bulletin_db (size_t num) |
220 | memset (&key, 0, sizeof key); | 220 | memset (&key, 0, sizeof key); |
221 | memset (&data, 0, sizeof data); | 221 | memset (&data, 0, sizeof data); |
222 | 222 | ||
223 | MU_DATUM_PTR(key) = username; | 223 | MU_DATUM_PTR (key) = username; |
224 | MU_DATUM_SIZE(key) = strlen (username); | 224 | MU_DATUM_SIZE (key) = strlen (username); |
225 | p = mu_umaxtostr (0, num); | 225 | p = mu_umaxtostr (0, num); |
226 | MU_DATUM_PTR(data) = p; | 226 | MU_DATUM_PTR (data) = p; |
227 | MU_DATUM_SIZE(data) = strlen (p); | 227 | MU_DATUM_SIZE (data) = strlen (p); |
228 | 228 | ||
229 | rc = mu_dbm_insert (db, key, data, 1); | 229 | rc = mu_dbm_insert (db, key, data, 1); |
230 | if (rc) | 230 | if (rc) |
... | @@ -274,44 +274,49 @@ deliver_pending_bulletins () | ... | @@ -274,44 +274,49 @@ deliver_pending_bulletins () |
274 | return; | 274 | return; |
275 | lastnum = get_last_delivered_num (); | 275 | lastnum = get_last_delivered_num (); |
276 | 276 | ||
277 | mu_mailbox_messages_count (bull, &total); | 277 | rc = mu_mailbox_messages_count (bull, &total); |
278 | 278 | if (rc) | |
279 | syslog (LOG_DEBUG, | 279 | mu_error (_("Cannot count bulletins: %s"), mu_strerror (rc)); |
280 | "user %s, last bulletin %lu, total bulletins %lu", | 280 | else |
281 | username, (unsigned long) lastnum, (unsigned long) total); | ||
282 | |||
283 | if (lastnum < total) | ||
284 | { | 281 | { |
285 | size_t i; | 282 | syslog (LOG_DEBUG, |
286 | size_t count = total - lastnum; | 283 | "user %s, last bulletin %lu, total bulletins %lu", |
284 | username, (unsigned long) lastnum, (unsigned long) total); | ||
285 | |||
286 | if (lastnum < total) | ||
287 | { | ||
288 | size_t i; | ||
289 | size_t count = total - lastnum; | ||
287 | 290 | ||
288 | syslog (LOG_INFO, | 291 | syslog (LOG_INFO, |
289 | ngettext ("user %s: delivering %lu pending bulletin", | 292 | ngettext ("user %s: delivering %lu pending bulletin", |
290 | "user %s: delivering %lu pending bulletins", | 293 | "user %s: delivering %lu pending bulletins", |
291 | count), | 294 | count), |
292 | username, (unsigned long) count); | 295 | username, (unsigned long) count); |
293 | 296 | ||
294 | for (i = lastnum + 1; i <= total; i++) | 297 | for (i = lastnum + 1; i <= total; i++) |
295 | { | ||
296 | int rc; | ||
297 | mu_message_t msg; | ||
298 | |||
299 | if ((rc = mu_mailbox_get_message (bull, i, &msg)) != 0) | ||
300 | { | 298 | { |
301 | mu_error (_("Cannot read bulletin %lu: %s"), | 299 | int rc; |
302 | (unsigned long) i, mu_strerror (rc)); | 300 | mu_message_t msg; |
303 | break; | 301 | |
304 | } | 302 | if ((rc = mu_mailbox_get_message (bull, i, &msg)) != 0) |
303 | { | ||
304 | mu_error (_("Cannot read bulletin %lu: %s"), | ||
305 | (unsigned long) i, mu_strerror (rc)); | ||
306 | break; | ||
307 | } | ||
305 | 308 | ||
306 | if ((rc = mu_mailbox_append_message (mbox, msg)) != 0) | 309 | if ((rc = mu_mailbox_append_message (mbox, msg)) != 0) |
307 | { | 310 | { |
308 | mu_error (_("Cannot append message %lu: %s"), | 311 | mu_error (_("Cannot append message %lu: %s"), |
309 | (unsigned long) i, mu_strerror (rc)); | 312 | (unsigned long) i, mu_strerror (rc)); |
310 | break; | 313 | break; |
314 | } | ||
311 | } | 315 | } |
316 | store_last_delivered_num (i - 1); | ||
312 | } | 317 | } |
313 | store_last_delivered_num (i - 1); | ||
314 | } | 318 | } |
319 | |||
315 | close_bulletin_mailbox (&bull); | 320 | close_bulletin_mailbox (&bull); |
316 | } | 321 | } |
317 | 322 | ... | ... |
-
Please register or sign in to post a comment