#include <sasl/saslutil.h>
#include <lib-sys/mutt_socket.h>
-#include <lib-ui/curses.h>
+#include <lib-ui/lib-ui.h>
#include "crypt.h"
#include "mutt.h"
*/
static pop_query_status _pop_query(pop_data_t *pop_data, char *buf, ssize_t buflen)
{
- char *c;
-
if (pop_data->status != POP_CONNECTED)
return PQ_NOT_CONNECTED;
mutt_socket_write(pop_data->conn, buf);
-
- c = strpbrk(buf, " \r\n");
- *c = '\0';
- snprintf(pop_data->err_msg, sizeof(pop_data->err_msg), "%s: ", buf);
+ snprintf(pop_data->err_msg, sizeof(pop_data->err_msg), "%.*s: ",
+ (int)(strpbrk(buf, " \r\n") - buf), buf);
if (mutt_socket_readln(buf, buflen, pop_data->conn) < 0) {
pop_data->status = POP_DISCONNECTED;
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;
}
attempts++;
break;
}
+ mutt_socket_close(pop_data->conn);
}
}
} else {
attempts++;
break;
}
+ mutt_socket_close(pop_data->conn);
}
}
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)
/* Check capabilities */
if (mode == 2) {
- char *msg = NULL;
+ const char *msg = NULL;
if (!pop_data->expire)
msg = _("Unable to leave messages on server.");
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;
}
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);
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);