aboutsummaryrefslogtreecommitdiff
path: root/libsylph/imap.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-07 08:37:31 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-10-07 08:37:31 +0000
commitd19d2c5d8874b947abc80b7aa29c7b19909006f7 (patch)
tree7f9b3f1b7095b12da753df3fb0fd28b6fef7476c /libsylph/imap.c
parent5f667d42f46f4735b0e23c00467055fc7d93df8e (diff)
support literals in IMAP response.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@627 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph/imap.c')
-rw-r--r--libsylph/imap.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/libsylph/imap.c b/libsylph/imap.c
index ead5d4c3..92926d3e 100644
--- a/libsylph/imap.c
+++ b/libsylph/imap.c
@@ -3109,6 +3109,8 @@ static gint imap_status(IMAPSession *session, IMAPFolder *folder,
real_path_);
ok = imap_cmd_ok(session, argbuf);
+ if (ok != IMAP_SUCCESS)
+ log_warning(_("error on imap command: STATUS\n"));
if (ok != IMAP_SUCCESS || !argbuf) THROW(ok);
str = search_array_str(argbuf, "STATUS");
@@ -3727,34 +3729,64 @@ static gint imap_cmd_ok(IMAPSession *session, GPtrArray *argbuf)
gchar *buf;
gint cmd_num;
gchar cmd_status[IMAPBUFSIZE + 1];
+ GString *str;
+ gchar *p;
+ gchar obuf[32];
+ gint len;
+ gchar *literal;
+
+ str = g_string_sized_new(256);
while ((ok = imap_cmd_gen_recv(session, &buf)) == IMAP_SUCCESS) {
- if (buf[0] == '*' && buf[1] == ' ') {
- if (argbuf) {
- g_memmove(buf, buf + 2, strlen(buf + 2) + 1);
- g_ptr_array_add(argbuf, buf);
- } else
+ g_string_append(str, buf);
+
+ if ((p = strrchr(buf, '{'))) {
+ /* literal */
+ p = strchr_cpy(p + 1, '}', obuf, sizeof(obuf));
+ len = atoi(obuf);
+ if (len < 0 || p != '\0') {
g_free(buf);
+ ok = IMAP_ERROR;
+ break;
+ }
+
+ literal = recv_bytes(SESSION(session)->sock, len);
+ if (!literal) {
+ g_free(buf);
+ ok = IMAP_SOCKET;
+ break;
+ }
+
+ g_string_append(str, "\r\n");
+ g_string_append_len(str, literal, len);
+ g_free(literal);
+ g_free(buf);
continue;
}
- if (sscanf(buf, "%d %" Xstr(IMAPBUFSIZE) "s",
+ g_free(buf);
+
+ if (str->str[0] == '*' && str->str[1] == ' ') {
+ if (argbuf)
+ g_ptr_array_add(argbuf, g_strdup(str->str + 2));
+
+ g_string_truncate(str, 0);
+ continue;
+ } else if (sscanf(str->str, "%d %" Xstr(IMAPBUFSIZE) "s",
&cmd_num, cmd_status) < 2) {
- g_free(buf);
- return IMAP_ERROR;
+ ok = IMAP_ERROR;
} else if (cmd_num == session->cmd_count &&
!strcmp(cmd_status, "OK")) {
if (argbuf)
- g_ptr_array_add(argbuf, buf);
- else
- g_free(buf);
- return IMAP_SUCCESS;
+ g_ptr_array_add(argbuf, g_strdup(str->str));
} else {
- g_free(buf);
- return IMAP_ERROR;
+ ok = IMAP_ERROR;
}
+
+ break;
}
+ g_string_free(str, TRUE);
return ok;
}