X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mx%2Fpop.c;h=ee18bc3910cf3aaf2340a3efd18e4a17474190b0;hp=2258d0fe5025d1fd28313e69d1aca81798a8a0a3;hb=98f62b5fcbd680fd5214ee85e1635b84322cbdd1;hpb=799c3f5aec72b8230f9c3c284e2b2e9d67ecf366 diff --git a/lib-mx/pop.c b/lib-mx/pop.c index 2258d0f..ee18bc3 100644 --- a/lib-mx/pop.c +++ b/lib-mx/pop.c @@ -7,7 +7,6 @@ * please see the file GPL in the top level source directory. */ -#include #include #include @@ -65,14 +64,11 @@ typedef struct { unsigned status : 2; unsigned capabilities : 1; - unsigned use_stls : 2; cmd_status cmd_capa : 2; /* optional command CAPA */ cmd_status cmd_stls : 2; /* optional command STLS */ cmd_status cmd_uidl : 2; /* optional command UIDL */ cmd_status cmd_top : 2; /* optional command TOP */ cmd_status cmd_user : 2; /* optional command USER */ - unsigned resp_codes : 1; /* server supports extended response codes */ - unsigned expire : 1; /* expire is greater than 0 */ unsigned clear_cache : 1; ssize_t size; @@ -560,8 +556,6 @@ static pop_query_status pop_capabilities(pop_data_t * pop_data, int mode) pop_data->cmd_uidl = CMD_NOT_AVAILABLE; pop_data->cmd_top = CMD_NOT_AVAILABLE; pop_data->cmd_user = CMD_NOT_AVAILABLE; - pop_data->resp_codes = 0; - pop_data->expire = 1; p_delete(&pop_data->auth_list); } @@ -591,11 +585,9 @@ static pop_query_status pop_capabilities(pop_data_t * pop_data, int mode) } /* Check capabilities */ - if (mode == 2) { + if (mode == 1) { const char *msg = NULL; - if (!pop_data->expire) - msg = _("Unable to leave messages on server."); if (pop_data->cmd_top == CMD_NOT_AVAILABLE) msg = _("Command TOP is not supported by server."); if (pop_data->cmd_uidl == CMD_NOT_AVAILABLE) @@ -668,37 +660,18 @@ static pop_query_status pop_open_connection (pop_data_t * pop_data) /* Attempt STLS if available and desired. */ if (!pop_data->conn->ssf && (pop_data->cmd_stls || mod_ssl.force_tls)) { - if (mod_ssl.force_tls) - pop_data->use_stls = 2; - if (pop_data->use_stls == 0) { - pop_data->use_stls = 1; - if (mod_ssl.starttls) - pop_data->use_stls = 2; + ret = pop_query(pop_data, buf, sizeof(buf), "STLS"); + if (ret == PQ_NOT_CONNECTED) + goto err_conn; + if (ret != PQ_OK) { + mutt_error ("%s", pop_data->err_msg); + mutt_sleep (2); } - if (pop_data->use_stls == 2) { - ret = pop_query(pop_data, buf, sizeof(buf), "STLS"); - if (ret == PQ_NOT_CONNECTED) - goto err_conn; - if (ret != PQ_OK) { - mutt_error ("%s", pop_data->err_msg); - mutt_sleep (2); - } - else if (mutt_ssl_starttls (pop_data->conn)) - { - mutt_error (_("Could not negotiate TLS connection")); - mutt_sleep (2); - return PQ_ERR; - } - else { - /* recheck capabilities after STLS completes */ - ret = pop_capabilities (pop_data, 1); - if (ret == PQ_NOT_CONNECTED) - goto err_conn; - if (ret == PQ_ERR) { - mutt_sleep (2); - return PQ_ERR; - } - } + else if (mutt_ssl_starttls (pop_data->conn)) + { + mutt_error (_("Could not negotiate TLS connection")); + mutt_sleep (2); + return PQ_ERR; } } @@ -717,7 +690,7 @@ static pop_query_status pop_open_connection (pop_data_t * pop_data) return ret; /* recheck capabilities after authentication */ - ret = pop_capabilities (pop_data, 2); + ret = pop_capabilities (pop_data, 1); if (ret == PQ_NOT_CONNECTED) goto err_conn; if (ret == PQ_ERR) { @@ -1179,6 +1152,112 @@ static int pop_sync_mailbox(CONTEXT * ctx, int unused, int *index_hint) } } +/* fetch message from POP server */ +static int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) +{ + int ret; + void *uidl; + char buf[LONG_STRING]; + char path[_POSIX_PATH_MAX]; + progress_t bar; + pop_data_t *pop_data = (pop_data_t *) ctx->data; + POP_CACHE *cache; + HEADER *h = ctx->hdrs[msgno]; + + /* see if we already have the message in our cache */ + cache = &pop_data->cache[h->index % POP_CACHE_LEN]; + + if (cache->path) { + if (cache->index == h->index) { + /* yes, so just return a pointer to the message */ + msg->fp = fopen (cache->path, "r"); + if (msg->fp) + return 0; + + mutt_perror (cache->path); + mutt_sleep (2); + return -1; + } + else { + /* clear the previous entry */ + unlink (cache->path); + p_delete(&cache->path); + } + } + + for (;;) { + if (pop_reconnect (ctx) != PQ_OK) + return -1; + + /* verify that massage index is correct */ + if (h->refno < 0) { + mutt_error + _("The message index is incorrect. Try reopening the mailbox."); + mutt_sleep (2); + return -1; + } + + bar.size = h->content->length + h->content->offset - 1; + bar.msg = _("Fetching message..."); + mutt_progress_bar (&bar, 0); + + 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); + return -1; + } + + snprintf(buf, sizeof(buf), "RETR %d\r\n", h->refno); + ret = pop_fetch_data(pop_data, buf, &bar, fetch_message, msg->fp); + if (ret == PQ_OK) + break; + + m_fclose(&msg->fp); + unlink (path); + + if (ret == PQ_ERR) { + mutt_error ("%s", pop_data->err_msg); + mutt_sleep (2); + return -1; + } + + if (ret == PFD_FUNCT_ERROR) { + mutt_error _("Can't write message to temporary file!"); + + mutt_sleep (2); + return -1; + } + } + + /* Update the header information. Previously, we only downloaded a + * portion of the headers, those required for the main display. + */ + cache->index = h->index; + cache->path = m_strdup(path); + rewind (msg->fp); + uidl = h->data; + envelope_delete(&h->env); + h->env = mutt_read_rfc822_header (msg->fp, h, 0, 0); + h->data = uidl; + h->lines = 0; + fgets (buf, sizeof (buf), msg->fp); + while (!feof (msg->fp)) { + ctx->hdrs[msgno]->lines++; + fgets (buf, sizeof (buf), msg->fp); + } + + h->content->length = ftello (msg->fp) - h->content->offset; + + /* This needs to be done in case this is a multipart message */ + h->security = crypt_query (h->content); + + mutt_clear_error (); + rewind (msg->fp); + + return 0; +} + /* }}} */ mx_t const pop_mx = { @@ -1189,6 +1268,7 @@ mx_t const pop_mx = { NULL, pop_open_mailbox, NULL, + pop_fetch_message, pop_acl_check, pop_check_mailbox, pop_close_mailbox, @@ -1346,110 +1426,4 @@ fail: p_delete(&pop_data); } -/* fetch message from POP server */ -int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) -{ - int ret; - void *uidl; - char buf[LONG_STRING]; - char path[_POSIX_PATH_MAX]; - progress_t bar; - pop_data_t *pop_data = (pop_data_t *) ctx->data; - POP_CACHE *cache; - HEADER *h = ctx->hdrs[msgno]; - - /* see if we already have the message in our cache */ - cache = &pop_data->cache[h->index % POP_CACHE_LEN]; - - if (cache->path) { - if (cache->index == h->index) { - /* yes, so just return a pointer to the message */ - msg->fp = fopen (cache->path, "r"); - if (msg->fp) - return 0; - - mutt_perror (cache->path); - mutt_sleep (2); - return -1; - } - else { - /* clear the previous entry */ - unlink (cache->path); - p_delete(&cache->path); - } - } - - for (;;) { - if (pop_reconnect (ctx) != PQ_OK) - return -1; - - /* verify that massage index is correct */ - if (h->refno < 0) { - mutt_error - _("The message index is incorrect. Try reopening the mailbox."); - mutt_sleep (2); - return -1; - } - - bar.size = h->content->length + h->content->offset - 1; - bar.msg = _("Fetching message..."); - mutt_progress_bar (&bar, 0); - - 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); - return -1; - } - - snprintf(buf, sizeof(buf), "RETR %d\r\n", h->refno); - ret = pop_fetch_data(pop_data, buf, &bar, fetch_message, msg->fp); - if (ret == PQ_OK) - break; - - m_fclose(&msg->fp); - unlink (path); - - if (ret == PQ_ERR) { - mutt_error ("%s", pop_data->err_msg); - mutt_sleep (2); - return -1; - } - - if (ret == PFD_FUNCT_ERROR) { - mutt_error _("Can't write message to temporary file!"); - - mutt_sleep (2); - return -1; - } - } - - /* Update the header information. Previously, we only downloaded a - * portion of the headers, those required for the main display. - */ - cache->index = h->index; - cache->path = m_strdup(path); - rewind (msg->fp); - uidl = h->data; - envelope_delete(&h->env); - h->env = mutt_read_rfc822_header (msg->fp, h, 0, 0); - h->data = uidl; - h->lines = 0; - fgets (buf, sizeof (buf), msg->fp); - while (!feof (msg->fp)) { - ctx->hdrs[msgno]->lines++; - fgets (buf, sizeof (buf), msg->fp); - } - - h->content->length = ftello (msg->fp) - h->content->offset; - - /* This needs to be done in case this is a multipart message */ - h->security = crypt_query (h->content); - - mutt_clear_error (); - rewind (msg->fp); - - return 0; -} - /* }}} */