int mutt_socket_readln(char *buf, ssize_t buflen, CONNECTION * conn);
int mutt_socket_write(CONNECTION * conn, const char *buf);
+int mutt_socket_readln2(buffer_t *buf, CONNECTION *conn);
+
int mutt_ssl_starttls (CONNECTION * conn);
int mutt_ssl_socket_setup (CONNECTION * 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)