/* 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; struct servent *service; /* Defaults */ acct->flags = 0; acct->type = M_ACCT_TYPE_POP; c = safe_strdup (path); url_parse_ciss (&url, c); if ((url.scheme != U_POP && url.scheme != U_POPS) || mutt_account_fromurl (acct, &url) < 0) { FREE(&c); mutt_error(_("Invalid POP URL: %s\n"), path); mutt_sleep(1); return -1; } if (url.scheme == U_POPS) acct->flags |= M_ACCT_SSL; service = getservbyname (url.scheme == U_POP ? "pop3" : "pop3s", "tcp"); if (service) acct->port = ntohs (service->s_port); else acct->port = url.scheme == U_POP ? POP_PORT : POP_SSL_PORT;; FREE (&c); return 0; }
/* imap_parse_path: given an IMAP mailbox name, return host, port * and a path IMAP servers will recognise. * mx.mbox is malloc'd, caller must free it */ int imap_parse_path (const char *path, IMAP_MBOX * mx) { static unsigned short ImapPort = 0; static unsigned short ImapsPort = 0; struct servent *service; ciss_url_t url; char *c; if (!ImapPort) { service = getservbyname ("imap", "tcp"); if (service) ImapPort = ntohs (service->s_port); else ImapPort = IMAP_PORT; debug_print (3, ("Using default IMAP port %d\n", ImapPort)); } if (!ImapsPort) { service = getservbyname ("imaps", "tcp"); if (service) ImapsPort = ntohs (service->s_port); else ImapsPort = IMAP_SSL_PORT; debug_print (3, ("Using default IMAPS port %d\n", ImapsPort)); } /* Defaults */ mx->account.flags = 0; mx->account.port = ImapPort; mx->account.type = M_ACCT_TYPE_IMAP; c = str_dup (path); url_parse_ciss (&url, c); if (!(url.scheme == U_IMAP || url.scheme == U_IMAPS) || mutt_account_fromurl (&mx->account, &url) < 0 || !*mx->account.host) { mem_free (&c); return -1; } mx->mbox = str_dup (url.path); if (url.scheme == U_IMAPS) mx->account.flags |= M_ACCT_SSL; mem_free (&c); if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT)) mx->account.port = ImapsPort; return 0; }
static int smtp_fill_account (ACCOUNT* account) { static unsigned short SmtpPort = 0; struct servent* service; ciss_url_t url; char* urlstr; account->flags = 0; account->port = 0; account->type = M_ACCT_TYPE_SMTP; urlstr = safe_strdup (SmtpUrl); url_parse_ciss (&url, urlstr); if ((url.scheme != U_SMTP && url.scheme != U_SMTPS) || mutt_account_fromurl (account, &url) < 0) { FREE (&urlstr); mutt_error (_("Invalid SMTP URL: %s"), SmtpUrl); mutt_sleep (1); return -1; } FREE (&urlstr); if (url.scheme == U_SMTPS) account->flags |= M_ACCT_SSL; if (!account->port) { if (account->flags & M_ACCT_SSL) account->port = SMTPS_PORT; else { if (!SmtpPort) { service = getservbyname ("smtp", "tcp"); if (service) SmtpPort = ntohs (service->s_port); else SmtpPort = SMTP_PORT; dprint (3, (debugfile, "Using default SMTP port %d\n", SmtpPort)); } account->port = SmtpPort; } } return 0; }
/* imap_parse_path: given an IMAP mailbox name, return host, port * and a path IMAP servers will recognise. * mx.mbox is malloc'd, caller must free it */ int imap_parse_path (const char* path, IMAP_MBOX* mx) { static unsigned short ImapPort = 0; static unsigned short ImapsPort = 0; struct servent* service; char tmp[128]; ciss_url_t url; char *c; int n; if (!ImapPort) { service = getservbyname ("imap", "tcp"); if (service) ImapPort = ntohs (service->s_port); else ImapPort = IMAP_PORT; dprint (3, (debugfile, "Using default IMAP port %d\n", ImapPort)); } if (!ImapsPort) { service = getservbyname ("imaps", "tcp"); if (service) ImapsPort = ntohs (service->s_port); else ImapsPort = IMAP_SSL_PORT; dprint (3, (debugfile, "Using default IMAPS port %d\n", ImapsPort)); } /* Defaults */ memset(&mx->account, 0, sizeof(mx->account)); mx->account.port = ImapPort; mx->account.type = M_ACCT_TYPE_IMAP; c = safe_strdup (path); url_parse_ciss (&url, c); if (url.scheme == U_IMAP || url.scheme == U_IMAPS) { if (mutt_account_fromurl (&mx->account, &url) < 0 || !*mx->account.host) { FREE (&c); return -1; } mx->mbox = safe_strdup (url.path); if (url.scheme == U_IMAPS) mx->account.flags |= M_ACCT_SSL; FREE (&c); } /* old PINE-compatibility code */ else { FREE (&c); if (sscanf (path, "{%127[^}]}", tmp) != 1) return -1; c = strchr (path, '}'); if (!c) return -1; else /* walk past closing '}' */ mx->mbox = safe_strdup (c+1); if ((c = strrchr (tmp, '@'))) { *c = '\0'; strfcpy (mx->account.user, tmp, sizeof (mx->account.user)); strfcpy (tmp, c+1, sizeof (tmp)); mx->account.flags |= M_ACCT_USER; } if ((n = sscanf (tmp, "%127[^:/]%127s", mx->account.host, tmp)) < 1) { dprint (1, (debugfile, "imap_parse_path: NULL host in %s\n", path)); FREE (&mx->mbox); return -1; } if (n > 1) { if (sscanf (tmp, ":%hu%127s", &(mx->account.port), tmp) >= 1) mx->account.flags |= M_ACCT_PORT; if (sscanf (tmp, "/%s", tmp) == 1) { if (!ascii_strncmp (tmp, "ssl", 3)) mx->account.flags |= M_ACCT_SSL; else { dprint (1, (debugfile, "imap_parse_path: Unknown connection type in %s\n", path)); FREE (&mx->mbox); return -1; } } } } if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT)) mx->account.port = ImapsPort; return 0; }