(util_msgset): Always return sorted msgset with no duplicates. Fixed transcript support.
Showing
1 changed file
with
36 additions
and
4 deletions
... | @@ -131,6 +131,12 @@ util_getfullpath (char *name, const char *delim) | ... | @@ -131,6 +131,12 @@ util_getfullpath (char *name, const char *delim) |
131 | return mu_normalize_path (p, delim); | 131 | return mu_normalize_path (p, delim); |
132 | } | 132 | } |
133 | 133 | ||
134 | static int | ||
135 | comp_int (const void *a, const void *b) | ||
136 | { | ||
137 | return *(int*)a - *(int*)b; | ||
138 | } | ||
139 | |||
134 | /* Return in set an allocated array contain (n) numbers, for imap messsage set | 140 | /* Return in set an allocated array contain (n) numbers, for imap messsage set |
135 | set ::= sequence_num / (sequence_num ":" sequence_num) / (set "," set) | 141 | set ::= sequence_num / (sequence_num ":" sequence_num) / (set "," set) |
136 | sequence_num ::= nz_number / "*" | 142 | sequence_num ::= nz_number / "*" |
... | @@ -151,6 +157,8 @@ util_msgset (char *s, size_t **set, int *n, int isuid) | ... | @@ -151,6 +157,8 @@ util_msgset (char *s, size_t **set, int *n, int isuid) |
151 | int done = 0; | 157 | int done = 0; |
152 | int status = 0; | 158 | int status = 0; |
153 | size_t max = 0; | 159 | size_t max = 0; |
160 | size_t *tmp; | ||
161 | int i,j; | ||
154 | 162 | ||
155 | status = mailbox_messages_count (mbox, &max); | 163 | status = mailbox_messages_count (mbox, &max); |
156 | if (status != 0) | 164 | if (status != 0) |
... | @@ -283,6 +291,14 @@ util_msgset (char *s, size_t **set, int *n, int isuid) | ... | @@ -283,6 +291,14 @@ util_msgset (char *s, size_t **set, int *n, int isuid) |
283 | return status; | 291 | return status; |
284 | } | 292 | } |
285 | } | 293 | } |
294 | |||
295 | qsort (*set, *n, sizeof (**set), comp_int); | ||
296 | |||
297 | tmp = *set; | ||
298 | for (i = 0, j = 1; i < *n; i++) | ||
299 | if (tmp[j-1] != (*set)[i]) | ||
300 | tmp[j++] = tmp[i]; | ||
301 | *n = j; | ||
286 | return 0; | 302 | return 0; |
287 | } | 303 | } |
288 | 304 | ||
... | @@ -347,9 +363,17 @@ util_out (int rc, const char *format, ...) | ... | @@ -347,9 +363,17 @@ util_out (int rc, const char *format, ...) |
347 | int status; | 363 | int status; |
348 | va_list ap; | 364 | va_list ap; |
349 | asprintf (&buf, "* %s%s\r\n", sc2string (rc), format); | 365 | asprintf (&buf, "* %s%s\r\n", sc2string (rc), format); |
350 | if (daemon_param.transcript) | ||
351 | syslog (LOG_DEBUG, "sent: %s", buf); | ||
352 | va_start (ap, format); | 366 | va_start (ap, format); |
367 | if (daemon_param.transcript) | ||
368 | { | ||
369 | char *buf1 = NULL; | ||
370 | vasprintf (&buf1, buf, ap); | ||
371 | if (buf1) | ||
372 | { | ||
373 | syslog (LOG_DEBUG, "sent: %s", buf1); | ||
374 | free (buf1); | ||
375 | } | ||
376 | } | ||
353 | status = vfprintf (ofile, buf, ap); | 377 | status = vfprintf (ofile, buf, ap); |
354 | va_end (ap); | 378 | va_end (ap); |
355 | free (buf); | 379 | free (buf); |
... | @@ -368,10 +392,18 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) | ... | @@ -368,10 +392,18 @@ util_finish (struct imap4d_command *command, int rc, const char *format, ...) |
368 | asprintf (&buf, "%s %s%s %s\r\n", command->tag, sc2string (rc), | 392 | asprintf (&buf, "%s %s%s %s\r\n", command->tag, sc2string (rc), |
369 | command->name, format); | 393 | command->name, format); |
370 | 394 | ||
395 | va_start (ap, format); | ||
371 | if (daemon_param.transcript) | 396 | if (daemon_param.transcript) |
372 | syslog (LOG_DEBUG, "send: %s", buf); | 397 | { |
398 | char *buf1 = NULL; | ||
399 | vasprintf (&buf1, buf, ap); | ||
400 | if (buf1) | ||
401 | { | ||
402 | syslog (LOG_DEBUG, "sent: %s", buf1); | ||
403 | free (buf1); | ||
404 | } | ||
405 | } | ||
373 | 406 | ||
374 | va_start (ap, format); | ||
375 | status = vfprintf (ofile, buf, ap); | 407 | status = vfprintf (ofile, buf, ap); |
376 | va_end (ap); | 408 | va_end (ap); |
377 | free (buf); | 409 | free (buf); | ... | ... |
-
Please register or sign in to post a comment