X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fcommand.c;h=e915320b4be5cb8b2bb7ee4ae4c9753509d439fc;hp=83ebbe73d00997f64b8d04d581f5d5362b9a91f4;hb=819c071fa7efc8dffb4dd92f36f0111227ff692f;hpb=1ee89902de184a640c171ae3285bff6882a791bd diff --git a/imap/command.c b/imap/command.c index 83ebbe7..e915320 100644 --- a/imap/command.c +++ b/imap/command.c @@ -13,10 +13,11 @@ * responses */ #include +#include #include "mutt.h" +#include "buffy.h" #include "message.h" -#include "mx.h" #include "imap_private.h" #include @@ -84,58 +85,32 @@ int imap_cmd_start (IMAP_DATA * idata, const char *cmd) int imap_cmd_step (IMAP_DATA * idata) { IMAP_COMMAND *cmd = &idata->cmd; - unsigned int len = 0; - int c; if (idata->status == IMAP_FATAL) { cmd_handle_fatal (idata); return IMAP_CMD_BAD; } - /* read into buffer, expanding buffer as necessary until we have a full - * line */ - do { - if (len == cmd->blen) { - p_realloc(&cmd->buf, cmd->blen + IMAP_CMD_BUFSIZE); - cmd->blen = cmd->blen + IMAP_CMD_BUFSIZE; - } - - if (len) - len--; - - c = mutt_socket_readln (cmd->buf + len, cmd->blen - len, idata->conn); - if (c <= 0) { - /* 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)) { - p_realloc(&cmd->buf, IMAP_CMD_BUFSIZE); - cmd->blen = IMAP_CMD_BUFSIZE; + buffer_reset(&cmd->buf); + if (mutt_socket_readln2(&cmd->buf, idata->conn) < 0) { + /* cmd_handle_fatal (idata); */ + return IMAP_CMD_BAD; } - idata->lastread = time (NULL); + idata->lastread = time(NULL); /* handle untagged messages. The caller still gets its shot afterwards. */ - if (!ascii_strncmp (cmd->buf, "* ", 2) && cmd_handle_untagged (idata)) + if (!m_strncmp(cmd->buf.data, "* ", 2) && cmd_handle_untagged (idata)) return IMAP_CMD_BAD; /* server demands a continuation response from us */ - if (cmd->buf[0] == '+') + if (cmd->buf.data[0] == '+') return IMAP_CMD_RESPOND; /* tagged completion code */ - if (!ascii_strncmp (cmd->buf, cmd->seq, SEQLEN)) { + if (!m_strncmp(cmd->buf.data, cmd->seq, SEQLEN)) { imap_cmd_finish (idata); - return imap_code (cmd->buf) ? IMAP_CMD_OK : IMAP_CMD_NO; + return imap_code(cmd->buf.data) ? IMAP_CMD_OK : IMAP_CMD_NO; } return IMAP_CMD_CONTINUE; @@ -209,16 +184,6 @@ int imap_exec (IMAP_DATA * idata, const char *cmd, int flags) return 0; } -/* imap_cmd_running: Returns whether an IMAP command is in progress. */ -int imap_cmd_running (IMAP_DATA * idata) -{ - if (idata->cmd.state == IMAP_CMD_CONTINUE || - idata->cmd.state == IMAP_CMD_RESPOND) - return 1; - - return 0; -} - /* imap_cmd_finish: Attempts to perform cleanup (eg fetch new mail if * detected, do expunge). Called automatically by imap_cmd_step, but * may be called at any time. Called by imap_check_mailbox just before @@ -288,7 +253,7 @@ static int cmd_handle_untagged (IMAP_DATA * idata) char *pn; int count; - s = imap_next_word (idata->cmd.buf); + s = imap_next_word (idata->cmd.buf.data); if ((idata->state == IMAP_SELECTED) && isdigit ((unsigned char) *s)) { pn = s; @@ -495,8 +460,6 @@ static void cmd_parse_fetch (IMAP_DATA * idata, char *s) static void cmd_parse_lsub (IMAP_DATA* idata, char* s) { char buf[STRING]; - char errstr[STRING]; - BUFFER err, token; ciss_url_t url; char *ep; @@ -527,18 +490,12 @@ static void cmd_parse_lsub (IMAP_DATA* idata, char* s) { if (s) { imap_unmunge_mbox_name (s); - m_strcpy(buf, sizeof(buf), "mailboxes \""); - mutt_account_tourl (&idata->conn->account, &url); + mutt_account_tourl(&idata->conn->account, &url); url.path = s; if (!m_strcmp(url.user, ImapUser)) url.user = NULL; - url_ciss_tostring (&url, buf + 11, sizeof (buf) - 10, 0); - m_strcat(buf, sizeof(buf), "\""); - p_clear(&token, 1); - err.data = errstr; - err.dsize = sizeof (errstr); - mutt_parse_rc_line (buf, &token, &err); - p_delete(&token.data); + url_ciss_tostring(&url, buf, sizeof(buf), 0); + buffy_do_mailboxes(buf, 1); } }