More bugfixes in imap4d.
* imap4d/authenticate.c (_auth_try): Fix call to p->handler. * imap4d/fetch.c (fetch_send_section_part): New argument close_bracket. Never print .PEEK, it confuses some clients (notably Thunderbird). I need to verify RFC, though. All callers updated. * imap4d/idle.c: Use imap4d_getline to get the reply, to avod modifying tok and command. * imap4d/imap4d.h (util_send_bytes, util_trim_nl): New prototypes. * imap4d/util.c (util_trim_nl): New function. (imap4d_getline): Use util_trim_nl.
Showing
6 changed files
with
44 additions
and
20 deletions
1 | 2008-08-11 Sergey Poznyakoff <gray@gnu.org.ua> | 1 | 2008-08-11 Sergey Poznyakoff <gray@gnu.org.ua> |
2 | 2 | ||
3 | More bugfixes in imap4d. | ||
4 | * imap4d/authenticate.c (_auth_try): Fix call to p->handler. | ||
5 | * imap4d/fetch.c (fetch_send_section_part): New argument | ||
6 | close_bracket. | ||
7 | Never print .PEEK, it confuses some clients (notably Thunderbird). | ||
8 | I need to verify RFC, though. | ||
9 | All callers updated. | ||
10 | * imap4d/idle.c: Use imap4d_getline to get the reply, to avod modifying | ||
11 | tok and command. | ||
12 | * imap4d/imap4d.h (util_send_bytes, util_trim_nl): New prototypes. | ||
13 | * imap4d/util.c (util_trim_nl): New function. | ||
14 | (imap4d_getline): Use util_trim_nl. | ||
15 | |||
16 | Bugfixes. | ||
3 | * imap4d/fetch.c (fetch_send_section_part): Make sure the item tag | 17 | * imap4d/fetch.c (fetch_send_section_part): Make sure the item tag |
4 | always reflects peek status. All callers updated. | 18 | always reflects peek status. All callers updated. |
5 | (fetch_io): Try to allocate as large a buffer as possible. | 19 | (fetch_io): Try to allocate as large a buffer as possible. | ... | ... |
... | @@ -81,8 +81,7 @@ _auth_try (void *item, void *data) | ... | @@ -81,8 +81,7 @@ _auth_try (void *item, void *data) |
81 | 81 | ||
82 | if (strcmp (p->name, ap->auth_type) == 0) | 82 | if (strcmp (p->name, ap->auth_type) == 0) |
83 | { | 83 | { |
84 | ap->result = p->handler (ap->command, | 84 | ap->result = p->handler (ap->command, ap->auth_type, &ap->username); |
85 | ap->auth_type, ap->arg, &ap->username); | ||
86 | return 1; | 85 | return 1; |
87 | } | 86 | } |
88 | return 0; | 87 | return 0; | ... | ... |
... | @@ -656,11 +656,11 @@ fetch_get_part (struct fetch_function_closure *ffc, | ... | @@ -656,11 +656,11 @@ fetch_get_part (struct fetch_function_closure *ffc, |
656 | 656 | ||
657 | static void | 657 | static void |
658 | fetch_send_section_part (struct fetch_function_closure *ffc, | 658 | fetch_send_section_part (struct fetch_function_closure *ffc, |
659 | const char *suffix) | 659 | const char *suffix, int close_bracket) |
660 | { | 660 | { |
661 | int i; | 661 | int i; |
662 | 662 | ||
663 | util_send ("BODY%s[", ffc->peek ? ".PEEK" : ""); | 663 | util_send ("BODY["); |
664 | for (i = 0; i < ffc->nset; i++) | 664 | for (i = 0; i < ffc->nset; i++) |
665 | { | 665 | { |
666 | if (i) | 666 | if (i) |
... | @@ -673,7 +673,8 @@ fetch_send_section_part (struct fetch_function_closure *ffc, | ... | @@ -673,7 +673,8 @@ fetch_send_section_part (struct fetch_function_closure *ffc, |
673 | util_send ("."); | 673 | util_send ("."); |
674 | util_send ("%s", suffix); | 674 | util_send ("%s", suffix); |
675 | } | 675 | } |
676 | util_send ("]"); | 676 | if (close_bracket) |
677 | util_send ("]"); | ||
677 | } | 678 | } |
678 | 679 | ||
679 | static int | 680 | static int |
... | @@ -868,7 +869,7 @@ _frt_body (struct fetch_function_closure *ffc, | ... | @@ -868,7 +869,7 @@ _frt_body (struct fetch_function_closure *ffc, |
868 | if (ffc->name) | 869 | if (ffc->name) |
869 | util_send ("%s", ffc->name); | 870 | util_send ("%s", ffc->name); |
870 | else | 871 | else |
871 | fetch_send_section_part (ffc, NULL); | 872 | fetch_send_section_part (ffc, NULL, 1); |
872 | msg = fetch_get_part (ffc, frt); | 873 | msg = fetch_get_part (ffc, frt); |
873 | if (!msg) | 874 | if (!msg) |
874 | { | 875 | { |
... | @@ -894,7 +895,7 @@ _frt_body_text (struct fetch_function_closure *ffc, | ... | @@ -894,7 +895,7 @@ _frt_body_text (struct fetch_function_closure *ffc, |
894 | if (ffc->name) | 895 | if (ffc->name) |
895 | util_send ("%s", ffc->name); | 896 | util_send ("%s", ffc->name); |
896 | else | 897 | else |
897 | fetch_send_section_part (ffc, "TEXT"); | 898 | fetch_send_section_part (ffc, "TEXT", 1); |
898 | msg = fetch_get_part (ffc, frt); | 899 | msg = fetch_get_part (ffc, frt); |
899 | if (!msg) | 900 | if (!msg) |
900 | { | 901 | { |
... | @@ -936,7 +937,7 @@ _frt_header0 (struct fetch_function_closure *ffc, | ... | @@ -936,7 +937,7 @@ _frt_header0 (struct fetch_function_closure *ffc, |
936 | if (ffc->name) | 937 | if (ffc->name) |
937 | util_send ("%s", ffc->name); | 938 | util_send ("%s", ffc->name); |
938 | else | 939 | else |
939 | fetch_send_section_part (ffc, suffix); | 940 | fetch_send_section_part (ffc, suffix, 1); |
940 | 941 | ||
941 | msg = fetch_get_part (ffc, frt); | 942 | msg = fetch_get_part (ffc, frt); |
942 | if (!msg) | 943 | if (!msg) |
... | @@ -973,7 +974,7 @@ _send_header_name (void *item, void *data) | ... | @@ -973,7 +974,7 @@ _send_header_name (void *item, void *data) |
973 | util_send (" "); | 974 | util_send (" "); |
974 | else | 975 | else |
975 | *pf = 1; | 976 | *pf = 1; |
976 | util_send ("\"%s\"", (char*) item); | 977 | util_send ("%s", (char*) item); |
977 | return 0; | 978 | return 0; |
978 | } | 979 | } |
979 | 980 | ||
... | @@ -1000,7 +1001,7 @@ _frt_header_fields (struct fetch_function_closure *ffc, | ... | @@ -1000,7 +1001,7 @@ _frt_header_fields (struct fetch_function_closure *ffc, |
1000 | 1001 | ||
1001 | set_seen (ffc, frt); | 1002 | set_seen (ffc, frt); |
1002 | 1003 | ||
1003 | fetch_send_section_part (ffc, "HEADER.FIELDS"); | 1004 | fetch_send_section_part (ffc, "HEADER.FIELDS", 0); |
1004 | if (ffc->not) | 1005 | if (ffc->not) |
1005 | util_send (".NOT"); | 1006 | util_send (".NOT"); |
1006 | util_send (" ("); | 1007 | util_send (" ("); | ... | ... |
... | @@ -22,6 +22,8 @@ int | ... | @@ -22,6 +22,8 @@ int |
22 | imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok) | 22 | imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok) |
23 | { | 23 | { |
24 | time_t start; | 24 | time_t start; |
25 | char *token_str = NULL; | ||
26 | size_t token_size = 0, token_len; | ||
25 | 27 | ||
26 | if (imap4d_tokbuf_argc (tok) != 2) | 28 | if (imap4d_tokbuf_argc (tok) != 2) |
27 | return util_finish (command, RESP_BAD, "Invalid arguments"); | 29 | return util_finish (command, RESP_BAD, "Invalid arguments"); |
... | @@ -37,10 +39,9 @@ imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok) | ... | @@ -37,10 +39,9 @@ imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok) |
37 | { | 39 | { |
38 | if (util_wait_input (5)) | 40 | if (util_wait_input (5)) |
39 | { | 41 | { |
40 | imap4d_readline (tok); | 42 | imap4d_getline (&token_str, &token_size, &token_len); |
41 | if (imap4d_tokbuf_argc (tok) == 1 | 43 | token_len = util_trim_nl (token_str, token_len); |
42 | && strcasecmp (imap4d_tokbuf_getarg (tok, IMAP4_ARG_TAG), | 44 | if (token_len == 4 && strcasecmp (token_str, "done") == 0) |
43 | "done") == 0) | ||
44 | break; | 45 | break; |
45 | } | 46 | } |
46 | else if (time (NULL) - start > idle_timeout) | 47 | else if (time (NULL) - start > idle_timeout) |
... | @@ -49,7 +50,7 @@ imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok) | ... | @@ -49,7 +50,7 @@ imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok) |
49 | imap4d_sync (); | 50 | imap4d_sync (); |
50 | util_flush_output (); | 51 | util_flush_output (); |
51 | } | 52 | } |
52 | 53 | free (token_str); | |
53 | return util_finish (command, RESP_OK, "terminated"); | 54 | return util_finish (command, RESP_OK, "terminated"); |
54 | } | 55 | } |
55 | 56 | ... | ... |
... | @@ -286,6 +286,7 @@ extern void imap4d_capability_init (void); | ... | @@ -286,6 +286,7 @@ extern void imap4d_capability_init (void); |
286 | /* Helper functions. */ | 286 | /* Helper functions. */ |
287 | extern int util_out (int, const char *, ...) MU_PRINTFLIKE(2,3); | 287 | extern int util_out (int, const char *, ...) MU_PRINTFLIKE(2,3); |
288 | extern int util_send (const char *, ...) MU_PRINTFLIKE(1,2); | 288 | extern int util_send (const char *, ...) MU_PRINTFLIKE(1,2); |
289 | extern int util_send_bytes (const char *buf, size_t size); | ||
289 | extern int util_send_qstring (const char *); | 290 | extern int util_send_qstring (const char *); |
290 | extern int util_send_literal (const char *); | 291 | extern int util_send_literal (const char *); |
291 | extern int util_start (char *); | 292 | extern int util_start (char *); |
... | @@ -341,6 +342,7 @@ void util_atexit (void (*fp) (void)); | ... | @@ -341,6 +342,7 @@ void util_atexit (void (*fp) (void)); |
341 | void util_chdir (const char *homedir); | 342 | void util_chdir (const char *homedir); |
342 | int is_atom (const char *s); | 343 | int is_atom (const char *s); |
343 | int util_isdelim (const char *str); | 344 | int util_isdelim (const char *str); |
345 | int util_trim_nl (char *s, size_t len); | ||
344 | 346 | ||
345 | #ifdef WITH_TLS | 347 | #ifdef WITH_TLS |
346 | int imap4d_init_tls_server (void); | 348 | int imap4d_init_tls_server (void); | ... | ... |
... | @@ -280,7 +280,7 @@ util_send (const char *format, ...) | ... | @@ -280,7 +280,7 @@ util_send (const char *format, ...) |
280 | if (!buf) | 280 | if (!buf) |
281 | imap4d_bye (ERR_NO_MEM); | 281 | imap4d_bye (ERR_NO_MEM); |
282 | 282 | ||
283 | #if 0 | 283 | #if 0 |
284 | if (imap4d_transcript) | 284 | if (imap4d_transcript) |
285 | mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf); | 285 | mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf); |
286 | #endif | 286 | #endif |
... | @@ -1416,6 +1416,16 @@ imap4d_tokbuf_from_string (char *str) | ... | @@ -1416,6 +1416,16 @@ imap4d_tokbuf_from_string (char *str) |
1416 | } | 1416 | } |
1417 | 1417 | ||
1418 | int | 1418 | int |
1419 | util_trim_nl (char *s, size_t len) | ||
1420 | { | ||
1421 | if (s && len > 0 && s[len - 1] == '\n') | ||
1422 | s[--len] = 0; | ||
1423 | if (s && len > 0 && s[len - 1] == '\r') | ||
1424 | s[--len] = 0; | ||
1425 | return len; | ||
1426 | } | ||
1427 | |||
1428 | int | ||
1419 | imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes) | 1429 | imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes) |
1420 | { | 1430 | { |
1421 | size_t len; | 1431 | size_t len; |
... | @@ -1423,10 +1433,7 @@ imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes) | ... | @@ -1423,10 +1433,7 @@ imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes) |
1423 | if (rc == 0) | 1433 | if (rc == 0) |
1424 | { | 1434 | { |
1425 | char *s = *pbuf; | 1435 | char *s = *pbuf; |
1426 | if (s && len > 0 && s[len - 1] == '\n') | 1436 | len = util_trim_nl (s, len); |
1427 | s[--len] = 0; | ||
1428 | if (s && len > 0 && s[len - 1] == '\r') | ||
1429 | s[--len] = 0; | ||
1430 | if (imap4d_transcript) | 1437 | if (imap4d_transcript) |
1431 | mu_diag_output (MU_DIAG_DEBUG, "recv: %s", s); | 1438 | mu_diag_output (MU_DIAG_DEBUG, "recv: %s", s); |
1432 | if (pnbytes) | 1439 | if (pnbytes) | ... | ... |
-
Please register or sign in to post a comment