Commit 28f1bd41 28f1bd413ec8ea818796f9c29edd5a43bec9c257 by Sergey Poznyakoff

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.
1 parent 30f0097c
2008-08-11 Sergey Poznyakoff <gray@gnu.org.ua>
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.
Bugfixes.
* imap4d/fetch.c (fetch_send_section_part): Make sure the item tag
always reflects peek status. All callers updated.
(fetch_io): Try to allocate as large a buffer as possible.
......
......@@ -81,8 +81,7 @@ _auth_try (void *item, void *data)
if (strcmp (p->name, ap->auth_type) == 0)
{
ap->result = p->handler (ap->command,
ap->auth_type, ap->arg, &ap->username);
ap->result = p->handler (ap->command, ap->auth_type, &ap->username);
return 1;
}
return 0;
......
......@@ -656,11 +656,11 @@ fetch_get_part (struct fetch_function_closure *ffc,
static void
fetch_send_section_part (struct fetch_function_closure *ffc,
const char *suffix)
const char *suffix, int close_bracket)
{
int i;
util_send ("BODY%s[", ffc->peek ? ".PEEK" : "");
util_send ("BODY[");
for (i = 0; i < ffc->nset; i++)
{
if (i)
......@@ -673,7 +673,8 @@ fetch_send_section_part (struct fetch_function_closure *ffc,
util_send (".");
util_send ("%s", suffix);
}
util_send ("]");
if (close_bracket)
util_send ("]");
}
static int
......@@ -868,7 +869,7 @@ _frt_body (struct fetch_function_closure *ffc,
if (ffc->name)
util_send ("%s", ffc->name);
else
fetch_send_section_part (ffc, NULL);
fetch_send_section_part (ffc, NULL, 1);
msg = fetch_get_part (ffc, frt);
if (!msg)
{
......@@ -894,7 +895,7 @@ _frt_body_text (struct fetch_function_closure *ffc,
if (ffc->name)
util_send ("%s", ffc->name);
else
fetch_send_section_part (ffc, "TEXT");
fetch_send_section_part (ffc, "TEXT", 1);
msg = fetch_get_part (ffc, frt);
if (!msg)
{
......@@ -936,7 +937,7 @@ _frt_header0 (struct fetch_function_closure *ffc,
if (ffc->name)
util_send ("%s", ffc->name);
else
fetch_send_section_part (ffc, suffix);
fetch_send_section_part (ffc, suffix, 1);
msg = fetch_get_part (ffc, frt);
if (!msg)
......@@ -973,7 +974,7 @@ _send_header_name (void *item, void *data)
util_send (" ");
else
*pf = 1;
util_send ("\"%s\"", (char*) item);
util_send ("%s", (char*) item);
return 0;
}
......@@ -1000,7 +1001,7 @@ _frt_header_fields (struct fetch_function_closure *ffc,
set_seen (ffc, frt);
fetch_send_section_part (ffc, "HEADER.FIELDS");
fetch_send_section_part (ffc, "HEADER.FIELDS", 0);
if (ffc->not)
util_send (".NOT");
util_send (" (");
......
......@@ -22,6 +22,8 @@ int
imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok)
{
time_t start;
char *token_str = NULL;
size_t token_size = 0, token_len;
if (imap4d_tokbuf_argc (tok) != 2)
return util_finish (command, RESP_BAD, "Invalid arguments");
......@@ -37,10 +39,9 @@ imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok)
{
if (util_wait_input (5))
{
imap4d_readline (tok);
if (imap4d_tokbuf_argc (tok) == 1
&& strcasecmp (imap4d_tokbuf_getarg (tok, IMAP4_ARG_TAG),
"done") == 0)
imap4d_getline (&token_str, &token_size, &token_len);
token_len = util_trim_nl (token_str, token_len);
if (token_len == 4 && strcasecmp (token_str, "done") == 0)
break;
}
else if (time (NULL) - start > idle_timeout)
......@@ -49,7 +50,7 @@ imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok)
imap4d_sync ();
util_flush_output ();
}
free (token_str);
return util_finish (command, RESP_OK, "terminated");
}
......
......@@ -286,6 +286,7 @@ extern void imap4d_capability_init (void);
/* Helper functions. */
extern int util_out (int, const char *, ...) MU_PRINTFLIKE(2,3);
extern int util_send (const char *, ...) MU_PRINTFLIKE(1,2);
extern int util_send_bytes (const char *buf, size_t size);
extern int util_send_qstring (const char *);
extern int util_send_literal (const char *);
extern int util_start (char *);
......@@ -341,6 +342,7 @@ void util_atexit (void (*fp) (void));
void util_chdir (const char *homedir);
int is_atom (const char *s);
int util_isdelim (const char *str);
int util_trim_nl (char *s, size_t len);
#ifdef WITH_TLS
int imap4d_init_tls_server (void);
......
......@@ -280,7 +280,7 @@ util_send (const char *format, ...)
if (!buf)
imap4d_bye (ERR_NO_MEM);
#if 0
#if 0
if (imap4d_transcript)
mu_diag_output (MU_DIAG_DEBUG, "sent: %s", buf);
#endif
......@@ -1416,6 +1416,16 @@ imap4d_tokbuf_from_string (char *str)
}
int
util_trim_nl (char *s, size_t len)
{
if (s && len > 0 && s[len - 1] == '\n')
s[--len] = 0;
if (s && len > 0 && s[len - 1] == '\r')
s[--len] = 0;
return len;
}
int
imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes)
{
size_t len;
......@@ -1423,10 +1433,7 @@ imap4d_getline (char **pbuf, size_t *psize, size_t *pnbytes)
if (rc == 0)
{
char *s = *pbuf;
if (s && len > 0 && s[len - 1] == '\n')
s[--len] = 0;
if (s && len > 0 && s[len - 1] == '\r')
s[--len] = 0;
len = util_trim_nl (s, len);
if (imap4d_transcript)
mu_diag_output (MU_DIAG_DEBUG, "recv: %s", s);
if (pnbytes)
......