- /* read into buffer, expanding buffer as necessary until we have a full
- * line */
- do {
- if (len == cmd->blen) {
- mem_realloc (&cmd->buf, cmd->blen + IMAP_CMD_BUFSIZE);
- cmd->blen = cmd->blen + IMAP_CMD_BUFSIZE;
- debug_print (3, ("grew buffer to %u bytes\n", cmd->blen));
- }
-
- if (len)
- len--;
-
- c = mutt_socket_readln (cmd->buf + len, cmd->blen - len, idata->conn);
- if (c <= 0) {
- debug_print (1, ("Error reading server response.\n"));
- /* cmd_handle_fatal (idata); */
- return IMAP_CMD_BAD;
- }
-
- len += c;
- }
- /* if we've read all the way to the end of the buffer, we haven't read a
- * full line (mutt_socket_readln strips the \r, so we always have at least
- * one character free when we've read a full line) */
- while (len == cmd->blen);
-
- /* don't let one large string make cmd->buf hog memory forever */
- if ((cmd->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) {
- mem_realloc (&cmd->buf, IMAP_CMD_BUFSIZE);
- cmd->blen = IMAP_CMD_BUFSIZE;
- debug_print (3, ("shrank buffer to %u bytes\n", cmd->blen));
+ buffer_reset(&cmd->buf);
+ if (mutt_socket_readln2(&cmd->buf, idata->conn) < 0) {
+ /* cmd_handle_fatal (idata); */
+ return IMAP_CMD_BAD;