X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..e0765f8ab8243c097213733be0d4be2a31448b89:/pop_lib.c diff --git a/pop_lib.c b/pop_lib.c index 4b06ab0..d8cc9ea 100644 --- a/pop_lib.c +++ b/pop_lib.c @@ -31,36 +31,45 @@ #include #include #include +#include /* given an POP mailbox name, return host, port, username and password */ int pop_parse_path (const char* path, ACCOUNT* acct) { ciss_url_t url; char *c; - int ret = -1; + struct servent *service; /* Defaults */ acct->flags = 0; - acct->port = POP_PORT; acct->type = M_ACCT_TYPE_POP; + acct->port = 0; c = safe_strdup (path); url_parse_ciss (&url, c); - if (url.scheme == U_POP || url.scheme == U_POPS) + if ((url.scheme != U_POP && url.scheme != U_POPS) || + mutt_account_fromurl (acct, &url) < 0) { - if (url.scheme == U_POPS) - { - acct->flags |= M_ACCT_SSL; - acct->port = POP_SSL_PORT; - } + FREE(&c); + mutt_error(_("Invalid POP URL: %s\n"), path); + mutt_sleep(1); + return -1; + } - if ((!url.path || !*url.path) && mutt_account_fromurl (acct, &url) == 0) - ret = 0; + if (url.scheme == U_POPS) + acct->flags |= M_ACCT_SSL; + + service = getservbyname (url.scheme == U_POP ? "pop3" : "pop3s", "tcp"); + if (!acct->port) { + if (service) + acct->port = ntohs (service->s_port); + else + acct->port = url.scheme == U_POP ? POP_PORT : POP_SSL_PORT;; } FREE (&c); - return ret; + return 0; } /* Copy error message to err_msg buffer */ @@ -489,7 +498,8 @@ int pop_fetch_data (POP_DATA *pop_data, char *query, progress_t *progressbar, strfcpy (inbuf + lenbuf, p, sizeof (buf)); pos += chunk; - if (chunk >= sizeof (buf)) + /* cast is safe since we break out of the loop when chunk<=0 */ + if ((size_t)chunk >= sizeof (buf)) { lenbuf += strlen (p); }