X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Fimap.c;h=4884a5ddbc46aa646683ed502d2379f6e9583559;hp=a684338d0ef9cbf8fce09e81d603166f970651c0;hb=f3ed92028a4873531d24eb1c317d276f165ac7a8;hpb=693d7da0cb3dd31a6486b581c89e6467cd71b2df diff --git a/src/imap.c b/src/imap.c index a684338d0..4884a5ddb 100644 --- a/src/imap.c +++ b/src/imap.c @@ -1737,10 +1737,23 @@ static gchar *imap_parse_atom(SockInfo *sock, gchar *src, gchar *dest, gint dest_len, GString *str) { gchar *cur_pos = src; + gchar *nextline; g_return_val_if_fail(str != NULL, cur_pos); - while (*cur_pos == ' ') cur_pos++; + /* read the next line if the current response buffer is empty */ + while (isspace(*cur_pos)) cur_pos++; + while (*cur_pos == '\0') { + if ((nextline = sock_getline(sock)) == NULL) + return cur_pos; + g_string_assign(str, nextline); + cur_pos = str->str; + strretchomp(nextline); + log_print("IMAP4< %s\n", nextline); + g_free(nextline); + + while (isspace(*cur_pos)) cur_pos++; + } if (!strncmp(cur_pos, "NIL", 3)) { *dest = '\0'; @@ -1753,21 +1766,27 @@ static gchar *imap_parse_atom(SockInfo *sock, gchar *src, } else if (*cur_pos == '{') { gchar buf[32]; gint len; - gchar *nextline; + gint line_len = 0; cur_pos = strchr_cpy(cur_pos + 1, '}', buf, sizeof(buf)); len = atoi(buf); - if ((nextline = sock_getline(sock)) == NULL) - return cur_pos; - strretchomp(nextline); - log_print("IMAP4< %s\n", nextline); - g_string_assign(str, nextline); + g_string_truncate(str, 0); + cur_pos = str->str; + + do { + if ((nextline = sock_getline(sock)) == NULL) + return cur_pos; + line_len += strlen(nextline); + g_string_append(str, nextline); + strretchomp(nextline); + log_print("IMAP4< %s\n", nextline); + g_free(nextline); + } while (line_len < len); - len = MIN(len, strlen(nextline)); - memcpy(dest, nextline, MIN(len, dest_len - 1)); + memcpy(dest, cur_pos, MIN(len, dest_len - 1)); dest[MIN(len, dest_len - 1)] = '\0'; - cur_pos = str->str + len; + cur_pos += len; } return cur_pos;