More cleanup in the fetch imap code.
Showing
4 changed files
with
55 additions
and
11 deletions
1 | 2001-05-11 Alain Magloire | ||
2 | |||
3 | * imap4d/fetch.c: More cleanup in the bodystructure code, | ||
4 | arrange response indentation etc ... | ||
5 | * impa4d/utils.c (util_send_string): New helper function. | ||
6 | |||
1 | 2001-05-10 Alain Magloire | 7 | 2001-05-10 Alain Magloire |
2 | 8 | ||
3 | * imap4d/fetch.c: Implemented INTERNALDATE. | 9 | * imap4d/fetch.c: Implemented INTERNALDATE. | ... | ... |
This diff is collapsed.
Click to expand it.
... | @@ -175,6 +175,7 @@ extern int imap4d_bye __P ((int)); | ... | @@ -175,6 +175,7 @@ extern int imap4d_bye __P ((int)); |
175 | /* Helper functions. */ | 175 | /* Helper functions. */ |
176 | extern int util_out __P ((int, const char *, ...)); | 176 | extern int util_out __P ((int, const char *, ...)); |
177 | extern int util_send __P ((const char *, ...)); | 177 | extern int util_send __P ((const char *, ...)); |
178 | extern int util_send_string __P ((const char *)); | ||
178 | extern int util_start __P ((char *)); | 179 | extern int util_start __P ((char *)); |
179 | extern int util_finish __P ((struct imap4d_command *, int, const char *, ...)); | 180 | extern int util_finish __P ((struct imap4d_command *, int, const char *, ...)); |
180 | extern int util_getstate __P ((void)); | 181 | extern int util_getstate __P ((void)); | ... | ... |
... | @@ -18,7 +18,7 @@ | ... | @@ -18,7 +18,7 @@ |
18 | #include "imap4d.h" | 18 | #include "imap4d.h" |
19 | #include <ctype.h> | 19 | #include <ctype.h> |
20 | 20 | ||
21 | static int add2set __P ((size_t **, int *, unsigned long, size_t)); | 21 | static int add2set __P ((size_t **, int *, unsigned long)); |
22 | static const char *sc2string __P ((int)); | 22 | static const char *sc2string __P ((int)); |
23 | 23 | ||
24 | /* Get the next space/CR/NL separated word, some words are between double | 24 | /* Get the next space/CR/NL separated word, some words are between double |
... | @@ -184,9 +184,6 @@ util_msgset (char *s, size_t **set, int *n, int isuid) | ... | @@ -184,9 +184,6 @@ util_msgset (char *s, size_t **set, int *n, int isuid) |
184 | status = mailbox_messages_count (mbox, &max); | 184 | status = mailbox_messages_count (mbox, &max); |
185 | if (status != 0) | 185 | if (status != 0) |
186 | return status; | 186 | return status; |
187 | /* The number after the "*" in an untagged FETCH response is always a | ||
188 | message sequence number, not a unique identifier, even for a UID | ||
189 | command response. But do what they meant not what they say. */ | ||
190 | /* If it is a uid sequence, override max with the UID. */ | 187 | /* If it is a uid sequence, override max with the UID. */ |
191 | if (isuid) | 188 | if (isuid) |
192 | { | 189 | { |
... | @@ -216,9 +213,23 @@ util_msgset (char *s, size_t **set, int *n, int isuid) | ... | @@ -216,9 +213,23 @@ util_msgset (char *s, size_t **set, int *n, int isuid) |
216 | } | 213 | } |
217 | if (low) | 214 | if (low) |
218 | { | 215 | { |
216 | /* Reverse it. */ | ||
217 | if (low > val) | ||
218 | { | ||
219 | long tmp = low; | ||
220 | tmp -= 2; | ||
221 | if (tmp <= 0 || val == 0) | ||
222 | { | ||
223 | free (*set); | ||
224 | *n = 0; | ||
225 | return EINVAL; | ||
226 | } | ||
227 | low = val; | ||
228 | val = tmp; | ||
229 | } | ||
219 | for (;low && low <= val; low++) | 230 | for (;low && low <= val; low++) |
220 | { | 231 | { |
221 | status = add2set (set, n, low, max); | 232 | status = add2set (set, n, low); |
222 | if (status != 0) | 233 | if (status != 0) |
223 | return status; | 234 | return status; |
224 | } | 235 | } |
... | @@ -226,7 +237,7 @@ util_msgset (char *s, size_t **set, int *n, int isuid) | ... | @@ -226,7 +237,7 @@ util_msgset (char *s, size_t **set, int *n, int isuid) |
226 | } | 237 | } |
227 | else | 238 | else |
228 | { | 239 | { |
229 | status = add2set(set, n, val, max); | 240 | status = add2set(set, n, val); |
230 | if (status != 0) | 241 | if (status != 0) |
231 | return status; | 242 | return status; |
232 | } | 243 | } |
... | @@ -284,9 +295,23 @@ util_msgset (char *s, size_t **set, int *n, int isuid) | ... | @@ -284,9 +295,23 @@ util_msgset (char *s, size_t **set, int *n, int isuid) |
284 | 295 | ||
285 | if (low) | 296 | if (low) |
286 | { | 297 | { |
298 | /* Reverse it. */ | ||
299 | if (low > val) | ||
300 | { | ||
301 | long tmp = low; | ||
302 | tmp -= 2; | ||
303 | if (tmp <= 0 || val == 0) | ||
304 | { | ||
305 | free (set); | ||
306 | *n = 0; | ||
307 | return EINVAL; | ||
308 | } | ||
309 | low = val; | ||
310 | val = tmp; | ||
311 | } | ||
287 | for (;low && low <= val; low++) | 312 | for (;low && low <= val; low++) |
288 | { | 313 | { |
289 | status = add2set (set, n, low, max); | 314 | status = add2set (set, n, low); |
290 | if (status != 0) | 315 | if (status != 0) |
291 | return status; | 316 | return status; |
292 | } | 317 | } |
... | @@ -306,6 +331,18 @@ util_send (const char *format, ...) | ... | @@ -306,6 +331,18 @@ util_send (const char *format, ...) |
306 | return status; | 331 | return status; |
307 | } | 332 | } |
308 | 333 | ||
334 | /* Send NIL if empty string, a literal if the string contains double quotes | ||
335 | or the string surrounded by double quotes. */ | ||
336 | int | ||
337 | util_send_string (const char *buffer) | ||
338 | { | ||
339 | if (*buffer == '\0') | ||
340 | return util_send ("NIL"); | ||
341 | if (strchr (buffer, '"')) | ||
342 | return util_send ("{%u}\r\n%s", strlen (buffer), buffer); | ||
343 | return util_send ("\"%s\"", buffer); | ||
344 | } | ||
345 | |||
309 | /* Send an unsolicited response. */ | 346 | /* Send an unsolicited response. */ |
310 | int | 347 | int |
311 | util_out (int rc, const char *format, ...) | 348 | util_out (int rc, const char *format, ...) |
... | @@ -417,7 +454,7 @@ imap4d_readline (FILE *fp) | ... | @@ -417,7 +454,7 @@ imap4d_readline (FILE *fp) |
417 | } | 454 | } |
418 | } | 455 | } |
419 | while (number > 0); | 456 | while (number > 0); |
420 | /* syslog (LOG_INFO, "readline: %s", line); */ | 457 | syslog (LOG_INFO, "readline: %s", line); |
421 | return line; | 458 | return line; |
422 | } | 459 | } |
423 | 460 | ||
... | @@ -522,11 +559,11 @@ sc2string (int rc) | ... | @@ -522,11 +559,11 @@ sc2string (int rc) |
522 | } | 559 | } |
523 | 560 | ||
524 | static int | 561 | static int |
525 | add2set (size_t **set, int *n, unsigned long val, size_t max) | 562 | add2set (size_t **set, int *n, unsigned long val) |
526 | { | 563 | { |
527 | int *tmp; | 564 | int *tmp; |
528 | if (val == 0 || val > max | 565 | tmp = realloc (*set, (*n + 1) * sizeof (**set)); |
529 | || (tmp = realloc (*set, (*n + 1) * sizeof (**set))) == NULL) | 566 | if (tmp == NULL) |
530 | { | 567 | { |
531 | if (*set) | 568 | if (*set) |
532 | free (*set); | 569 | free (*set); | ... | ... |
-
Please register or sign in to post a comment