X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=pop.c;h=a066f6e5dd05562de916dd3f760a506e089e4613;hp=3cfb694dc93d0b1e435433076d373985741ac97f;hb=981e10e224fde4de5d40adcee1deda89df2715ca;hpb=5a44e401b4e50f378f9caa045fe6ad6ca652b758 diff --git a/pop.c b/pop.c index 3cfb694..a066f6e 100644 --- a/pop.c +++ b/pop.c @@ -13,7 +13,7 @@ #include #include -#include +#include #include "crypt.h" #include "mutt.h" @@ -155,7 +155,7 @@ static pop_query_status pop_connect(pop_data_t * pop_data) p_delete(&pop_data->timestamp); if ((p = strchr(buf, '<')) && (q = strchr(p, '>'))) { - pop_data->timestamp = p_dupstr(p, q - p); + pop_data->timestamp = p_dupstr(p, q + 1 - p); } return PQ_OK; } @@ -416,6 +416,7 @@ static pop_query_status pop_authenticate (pop_data_t * pop_data) attempts++; break; } + mutt_socket_close(pop_data->conn); } } } else { @@ -431,6 +432,7 @@ static pop_query_status pop_authenticate (pop_data_t * pop_data) attempts++; break; } + mutt_socket_close(pop_data->conn); } } @@ -454,55 +456,48 @@ static pop_query_status pop_fetch_data(pop_data_t *pop_data, const char *query, progress_t *bar, int (*funct)(char *, void *), void *data) { - char buf[LONG_STRING]; - char *inbuf; - char *p; - pop_query_status ret; - int chunk = 0; - long pos = 0; - ssize_t lenbuf = 0; + pop_query_status ret; + char buf[LONG_STRING]; + buffer_t inbuf; + ssize_t pos = 0; - m_strcpy(buf, sizeof(buf), query); - ret = _pop_query(pop_data, buf, sizeof(buf)); - if (ret != PQ_OK) - return ret; + buffer_init(&inbuf); - inbuf = p_new(char, sizeof(buf)); + m_strcpy(buf, sizeof(buf), query); + ret = _pop_query(pop_data, buf, sizeof(buf)); + if (ret != PQ_OK) + return ret; - for (;;) { - chunk = - mutt_socket_readln(buf, sizeof (buf), pop_data->conn); - if (chunk < 0) { - pop_data->status = POP_DISCONNECTED; - ret = PQ_NOT_CONNECTED; - break; - } + for (;;) { + int dot = 0; - p = buf; - if (!lenbuf && buf[0] == '.') { - if (buf[1] != '.') - break; - p++; - } + if (mutt_socket_readln2(&inbuf, pop_data->conn) < 0) { + pop_data->status = POP_DISCONNECTED; + ret = PQ_NOT_CONNECTED; + break; + } - m_strcpy(inbuf + lenbuf,sizeof(buf), p); - pos += chunk; + if (bar) { + mutt_progress_bar(bar, pos += inbuf.len); + } - if (chunk >= ssizeof(buf)) { - lenbuf += strlen (p); - } else { - if (bar) - mutt_progress_bar (bar, pos); - if (ret == 0 && funct (inbuf, data) < 0) - ret = PFD_FUNCT_ERROR; - lenbuf = 0; - } + if (inbuf.data[0] == '.') { + if (inbuf.data[1] != '.') + break; + dot = 1; + } - p_realloc(&inbuf, lenbuf + sizeof(buf)); - } + if (funct(inbuf.data + dot, data) < 0) { + buffer_wipe(&inbuf); + ret = PFD_FUNCT_ERROR; + break; + } - p_delete(&inbuf); - return ret; + buffer_reset(&inbuf); + } + + buffer_wipe(&inbuf); + return ret; } static int fetch_capa (char *line, void *data) @@ -597,7 +592,7 @@ static pop_query_status pop_capabilities(pop_data_t * pop_data, int mode) /* Check capabilities */ if (mode == 2) { - char *msg = NULL; + const char *msg = NULL; if (!pop_data->expire) msg = _("Unable to leave messages on server."); @@ -632,7 +627,7 @@ static int pop_parse_path (const char *path, ACCOUNT * act) if (url.scheme == U_POP || url.scheme == U_POPS) { if (url.scheme == U_POPS) { - act->flags |= M_ACCT_SSL; + act->has_ssl = 1; act->port = POP_SSL_PORT; } @@ -1217,18 +1212,18 @@ void pop_fetch_mail (void) pop_data_t *pop_data; ssize_t plen; - if (!PopHost) { + if (m_strisempty(PopHost)) { mutt_error _("POP host is not defined."); return; } plen = m_strlen(PopHost) + 7; - url = p = p_new(char, plen); + url = p = p_new(char, plen); if (url_check_scheme (PopHost) == U_UNKNOWN) { - plen -= m_strcpy(url, plen, "pop://"); - p += plen; + snprintf(p, plen, "pop://%s", PopHost); + } else { + m_strcpy(p, plen, PopHost); } - m_strcpy(p, plen, PopHost); ret = pop_parse_path (url, &act); p_delete(&url); @@ -1400,7 +1395,7 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) bar.msg = _("Fetching message..."); mutt_progress_bar (&bar, 0); - msg->fp = m_tempfile(path, sizeof(path), NONULL(MCore.tmpdir), NULL); + msg->fp = m_tempfile(path, sizeof(path), NONULL(mod_core.tmpdir), NULL); if (!msg->fp) { mutt_error(_("Could not create temporary file")); mutt_sleep(2);