Commit 9a419c50 9a419c505d4e72bea50fe33de1aab1d82fde4f82 by Sergey Poznyakoff

imap client: reflect changes to imapio parser.

* include/mailutils/sys/imap.h (_mu_imap_seterrstrz): New proto.
* libmailutils/imapio/replstr.c: Update.
* libproto/imap/err.c (_mu_imap_seterrstrz): New function.
* libproto/imap/id.c: Remove superfluous calls to _mu_imap_seterrstr.
* libproto/imap/login.c: Likewise.
* libproto/imap/select.c: Likewise.
* libproto/imap/status.c: Likewise.
* libproto/imap/response.c: Set human-readable text as errstr.
* libproto/imap/resproc.c (ok_response): Reflect changes to
mu_imapio_getline.
1 parent 54eb0674
......@@ -48,7 +48,7 @@ int mu_imapio_reply_string (struct _mu_imapio *io, size_t start, char **pbuf);
int mu_imap_flag_to_attribute (const char *item, int *attr);
int mu_imap_format_flags (mu_stream_t str, int flags);
#ifdef __cplusplus
}
#endif
......
......@@ -155,6 +155,7 @@ int _mu_imap_xscript_level (mu_imap_t imap, int xlev);
while (0)
int _mu_imap_seterrstr (mu_imap_t imap, const char *str, size_t len);
int _mu_imap_seterrstrz (mu_imap_t imap, const char *str);
void _mu_imap_clrerrstr (mu_imap_t imap);
int _mu_imap_tag_next (mu_imap_t imap);
......
......@@ -21,7 +21,8 @@
#include <mailutils/argcv.h>
#include <mailutils/sys/imapio.h>
/* FIXME: It would be good to have a `, size_t *psize' argument, to allow
/* FIXME: 1. Is it needed at all?
2. It would be good to have a `, size_t *psize' argument, to allow
for passing an already allocated buffer. This implies similar changes
to mu_argcv_join. */
int
......
......@@ -41,6 +41,12 @@ _mu_imap_seterrstr (mu_imap_t imap, const char *str, size_t len)
return 0;
}
int
_mu_imap_seterrstrz (mu_imap_t imap, const char *str)
{
return _mu_imap_seterrstr (imap, str, strlen (str));
}
void
_mu_imap_clrerrstr (mu_imap_t imap)
{
......
......@@ -147,11 +147,6 @@ mu_imap_id (mu_imap_t imap, char **idenv, mu_assoc_t *passoc)
case MU_IMAP_BAD:
status = MU_ERR_BADREPLY;
if (mu_imapio_reply_string (imap->io, 2, &p) == 0)
{
_mu_imap_seterrstr (imap, p, strlen (p));
free (p);
}
break;
}
imap->state = MU_IMAP_CONNECTED;
......
......@@ -69,11 +69,6 @@ mu_imap_login (mu_imap_t imap, const char *user, const char *pass)
case MU_IMAP_BAD:
status = MU_ERR_BADREPLY;
if (mu_imapio_reply_string (imap->io, 2, &p) == 0)
{
_mu_imap_seterrstr (imap, p, strlen (p));
free (p);
}
break;
}
imap->state = MU_IMAP_CONNECTED;
......
......@@ -27,6 +27,13 @@
#include <mailutils/errno.h>
#include <mailutils/sys/imap.h>
static void
response_to_errstr (mu_imap_t imap, size_t argc, char **argv)
{
if (argc && strcmp (argv[argc-1], "]"))
_mu_imap_seterrstrz (imap, argv[argc-1]);
}
int
_mu_imap_response (mu_imap_t imap)
{
......@@ -50,7 +57,6 @@ _mu_imap_response (mu_imap_t imap)
{
char **wv;
size_t wc;
char *p;
mu_imapio_get_words (imap->io, &wc, &wv);
if (strcmp (wv[0], "*") == 0)
......@@ -70,29 +76,17 @@ _mu_imap_response (mu_imap_t imap)
else if (strcmp (wv[1], "OK") == 0)
{
imap->resp_code = MU_IMAP_OK;
if (mu_imapio_reply_string (imap->io, 2, &p) == 0)
{
_mu_imap_seterrstr (imap, p, strlen (p));
free (p);
}
response_to_errstr (imap, wc, wv);
}
else if (strcmp (wv[1], "NO") == 0)
{
imap->resp_code = MU_IMAP_NO;
if (mu_imapio_reply_string (imap->io, 2, &p) == 0)
{
_mu_imap_seterrstr (imap, p, strlen (p));
free (p);
}
response_to_errstr (imap, wc, wv);
}
else if (strcmp (wv[1], "BAD") == 0)
{
imap->resp_code = MU_IMAP_BAD;
if (mu_imapio_reply_string (imap->io, 2, &p) == 0)
{
_mu_imap_seterrstr (imap, p, strlen (p));
free (p);
}
response_to_errstr (imap, wc, wv);
}
else
status = MU_ERR_BADREPLY;
......
......@@ -63,20 +63,25 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
arg = _mu_imap_list_at (resp, 1);
if (!arg)
return;
if (arg->type == imap_eltype_string && arg->v.string[0] == '[')
if (_mu_imap_list_element_is_string (arg, "["))
{
char *p;
size_t len = strcspn (arg->v.string, "]");
arg = _mu_imap_list_at (resp, 2);
if (!arg || arg->type != imap_eltype_string)
return;
if (mu_kwd_xlat_name_len (mu_imap_response_codes,
arg->v.string + 1, len - 1, &rcode))
if (mu_kwd_xlat_name (mu_imap_response_codes, arg->v.string, &rcode))
rcode = -1;
arg = _mu_imap_list_at (resp, 4);
if (!arg || !_mu_imap_list_element_is_string (arg, "]"))
return;
switch (rcode)
{
case MU_IMAP_RESPONSE_PERMANENTFLAGS:
arg = _mu_imap_list_at (resp, 2);
arg = _mu_imap_list_at (resp, 3);
if (!arg ||
_mu_imap_collect_flags (arg, &imap->mbox_stat.permanent_flags))
break;
......@@ -86,11 +91,11 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
return;
case MU_IMAP_RESPONSE_UIDNEXT:
arg = _mu_imap_list_at (resp, 2);
arg = _mu_imap_list_at (resp, 3);
if (!arg || arg->type != imap_eltype_string)
break;
n = strtoul (arg->v.string, &p, 10);
if (*p == ']')
if (*p == 0)
{
imap->mbox_stat.uidnext = n;
imap->mbox_stat.flags |= MU_IMAP_STAT_UIDNEXT;
......@@ -100,11 +105,11 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
return;
case MU_IMAP_RESPONSE_UIDVALIDITY:
arg = _mu_imap_list_at (resp, 2);
arg = _mu_imap_list_at (resp, 3);
if (!arg || arg->type != imap_eltype_string)
break;
n = strtoul (arg->v.string, &p, 10);
if (*p == ']')
if (*p == 0)
{
imap->mbox_stat.uidvalidity = n;
imap->mbox_stat.flags |= MU_IMAP_STAT_UIDVALIDITY;
......@@ -114,11 +119,11 @@ ok_response (mu_imap_t imap, mu_list_t resp, void *data)
return;
case MU_IMAP_RESPONSE_UNSEEN:
arg = _mu_imap_list_at (resp, 2);
arg = _mu_imap_list_at (resp, 3);
if (!arg || arg->type != imap_eltype_string)
break;
n = strtoul (arg->v.string, &p, 10);
if (*p == ']')
if (*p == 0)
{
imap->mbox_stat.first_unseen = n;
imap->mbox_stat.flags |= MU_IMAP_STAT_FIRST_UNSEEN;
......
......@@ -138,11 +138,6 @@ mu_imap_select (mu_imap_t imap, const char *mbox, int writable,
case MU_IMAP_BAD:
status = MU_ERR_BADREPLY;
if (mu_imapio_reply_string (imap->io, 2, &p) == 0)
{
_mu_imap_seterrstr (imap, p, strlen (p));
free (p);
}
break;
}
imap->state = MU_IMAP_CONNECTED;
......
......@@ -201,11 +201,6 @@ mu_imap_status (mu_imap_t imap, const char *mboxname, struct mu_imap_stat *ps)
case MU_IMAP_BAD:
status = MU_ERR_BADREPLY;
if (mu_imapio_reply_string (imap->io, 2, &p) == 0)
{
_mu_imap_seterrstr (imap, p, strlen (p));
free (p);
}
break;
}
imap->state = MU_IMAP_CONNECTED;
......