/* remote host account manipulation (POP/IMAP) */
-#include "account.h"
#include "mutt.h"
+#include "account.h"
+#include "url.h"
/* mutt_account_match: compare account info (host/port/user) */
int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
return 1;
}
+/* mutt_account_fromurl: fill account with information from url. */
+int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url)
+{
+ /* must be present */
+ if (url->host)
+ strfcpy (account->host, url->host, sizeof (account->host));
+ else
+ return -1;
+
+ if (url->user)
+ {
+ strfcpy (account->user, url->user, sizeof (account->user));
+ account->flags |= M_ACCT_USER;
+ }
+ if (url->pass)
+ {
+ strfcpy (account->pass, url->pass, sizeof (account->pass));
+ account->flags |= M_ACCT_PASS;
+ }
+ if (url->port)
+ {
+ account->port = url->port;
+ account->flags |= M_ACCT_PORT;
+ }
+
+ return 0;
+}
+
/* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
int mutt_account_getuser (ACCOUNT* account)
{
#ifndef _MUTT_ACCOUNT_H_
#define _MUTT_ACCOUNT_H_ 1
+#include "url.h"
+
/* account types */
enum
{
} ACCOUNT;
int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* m2);
+int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url);
int mutt_account_getuser (ACCOUNT* account);
int mutt_account_getpass (ACCOUNT* account);
FOLDER *folder = (FOLDER *) data;
struct passwd *pw;
struct group *gr;
+ int optional = (flags & M_FORMAT_OPTIONAL);
switch (op)
{
#ifdef USE_IMAP
if (mx_is_imap (folder->ff->desc))
{
- snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
- snprintf (dest, destlen, tmp, folder->ff->new);
+ if (!optional)
+ {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, folder->ff->new);
+ }
+ else if (!folder->ff->new)
+ optional = 0;
break;
}
#endif
snprintf (dest, destlen, tmp, op);
break;
}
+
+ if (optional)
+ mutt_FormatString (dest, destlen, ifstring, folder_format_str, data, 0);
+ else if (flags & M_FORMAT_OPTIONAL)
+ mutt_FormatString (dest, destlen, elsestring, folder_format_str, data, 0);
+
return (src);
}
IMAP_DATA* idata;
ACCOUNT* creds;
- conn = mutt_conn_find (NULL, account);
+ if (!(conn = mutt_conn_find (NULL, account)))
+ return NULL;
+
/* if opening a new UNSELECTED connection, preserve existing creds */
creds = &(conn->account);
if (flags & M_IMAP_CONN_NOSELECT)
while (conn->data && ((IMAP_DATA*) conn->data)->state == IMAP_SELECTED)
{
- conn = mutt_conn_find (conn, account);
+ if (!(conn = mutt_conn_find (conn, account)))
+ return NULL;
memcpy (&(conn->account), creds, sizeof (ACCOUNT));
}
-
idata = (IMAP_DATA*) conn->data;
/* don't open a new connection if one isn't wanted */
/* reformat path for IMAP list, and append wildcard */
/* don't use INBOX in place of "" */
- if (mx.mbox[0])
+ if (mx.mbox && mx.mbox[0])
imap_fix_path (idata, mx.mbox, list, sizeof(list));
else
list[0] = '\0';
imap_cmd_start (idata, buf);
/* and see what the results are */
- strfcpy (completion, mx.mbox, sizeof(completion));
+ strfcpy (completion, NONULL(mx.mbox), sizeof(completion));
do
{
if (imap_parse_list_response(idata, &list_word, &noselect, &noinferiors,
return n;
}
-void imap_set_ssl (ACCOUNT* account)
-{
- if (! (account->flags & M_ACCT_PORT))
- account->port = IMAP_SSL_PORT;
- account->flags |= M_ACCT_SSL;
-}
-
static int ssl_socket_open_err (CONNECTION *conn)
{
mutt_error (_("SSL disabled due the lack of entropy"));
extern char *SslEntropyFile;
extern int ssl_socket_setup (CONNECTION *conn);
-extern void imap_set_ssl (ACCOUNT* account);
#endif /* _MUTT_SSL_H_ */
#include "mutt.h"
#include "mx.h" /* for M_IMAP */
+#include "url.h"
#include "imap_private.h"
#include "imap_ssl.h"
int imap_parse_path (const char* path, IMAP_MBOX* mx)
{
char tmp[128];
+ url_scheme_t scheme;
+ ciss_url_t url;
char *c;
int n;
-
- if (sscanf (path, "{%128[^}]}", tmp) != 1)
- return -1;
-
- mx->account.type = M_ACCT_TYPE_IMAP;
- c = strchr (path, '}');
- if (!c)
- return -1;
- else
- /* walk past closing '}' */
- mx->mbox = safe_strdup (c+1);
-
/* Defaults */
mx->account.flags = 0;
mx->account.port = IMAP_PORT;
+ mx->account.type = M_ACCT_TYPE_IMAP;
+
+#ifdef USE_SSL
+ if (option (OPTIMAPFORCESSL))
+ mx->account.flags |= M_ACCT_SSL;
+#endif
- if ((c = strrchr (tmp, '@')))
+ scheme = url_check_scheme (NONULL (path));
+ if (scheme == U_IMAP || scheme == U_IMAPS)
{
- *c = '\0';
- strfcpy (mx->account.user, tmp, sizeof (mx->account.user));
- strfcpy (tmp, c+1, sizeof (tmp));
- mx->account.flags |= M_ACCT_USER;
+ if (url_parse_ciss (&url, path) < 0)
+ return -1;
+
+ n = mutt_account_fromurl (&mx->account, &url);
+ FREE (&url.user);
+ FREE (&url.pass);
+ FREE (&url.host);
+
+ if (n < 0)
+ {
+ FREE (&url.path);
+ return -1;
+ }
+
+ mx->mbox = url.path;
+
+ if (scheme == U_IMAPS)
+ mx->account.flags |= M_ACCT_SSL;
}
-
- if ((n = sscanf (tmp, "%128[^:/]%128s", mx->account.host, tmp)) < 1)
+ /* old PINE-compatibility code */
+ else
{
- dprint (1, (debugfile, "imap_parse_path: NULL host in %s\n", path));
- FREE (&mx->mbox);
- return -1;
- }
+ if (sscanf (path, "{%128[^}]}", tmp) != 1)
+ return -1;
+
+ c = strchr (path, '}');
+ if (!c)
+ return -1;
+ else
+ /* walk past closing '}' */
+ mx->mbox = safe_strdup (c+1);
- if (n > 1) {
- if (sscanf (tmp, ":%hd%128s", &(mx->account.port), tmp) >= 1)
- mx->account.flags |= M_ACCT_PORT;
- if (sscanf (tmp, "/%s", tmp) == 1)
+ if ((c = strrchr (tmp, '@')))
{
-#ifdef USE_SSL
- if (!strncmp (tmp, "ssl", 3))
- imap_set_ssl (&(mx->account));
- else
-#endif
+ *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, "%128[^:/]%128s", 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, ":%hd%128s", &(mx->account.port), tmp) >= 1)
+ mx->account.flags |= M_ACCT_PORT;
+ if (sscanf (tmp, "/%s", tmp) == 1)
{
- dprint (1, (debugfile, "imap_parse_path: Unknown connection type in %s\n", path));
- FREE (&mx->mbox);
- return -1;
+ if (!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;
+ }
}
}
}
-
-#ifdef USE_SSL
- if (option (OPTIMAPFORCESSL))
- imap_set_ssl (&(mx->account));
-#endif
+
+ if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
+ mx->account.port = IMAP_SSL_PORT;
return 0;
}
conn->next = Connections;
Connections = conn;
-#ifdef USE_SSL
if (account->flags & M_ACCT_SSL)
+ {
+#ifdef USE_SSL
ssl_socket_setup (conn);
- else
+#else
+ mutt_error _("SSL is unavailable.");
+ sleep (2);
+ FREE (&conn);
+
+ return NULL;
#endif
+ }
+ else
{
conn->read = raw_socket_read;
conn->write = raw_socket_write;
#include "mailbox.h"
#include "copy.h"
#include "keymap.h"
-
+#include "url.h"
#ifdef HAVE_PGP
#include "pgp.h"
int mx_is_imap(const char *p)
{
- return p && (*p == '{');
+ url_scheme_t scheme;
+
+ if (!p)
+ return 0;
+
+ if (*p == '{')
+ return 1;
+
+ scheme = url_check_scheme (p);
+ if (scheme == U_IMAP || scheme == U_IMAPS)
+ return 1;
+
+ return 0;
}
#endif
static struct mapping_t UrlMap[] =
{
{ "file", U_FILE },
-#ifdef USE_IMAP
{ "imap", U_IMAP },
-#endif
-#ifdef USE_POP
- { "pop", U_POP },
-#endif
-#ifdef USE_SSL
-# ifdef USE_IMAP
{ "imaps", U_IMAPS },
-# endif
-# ifdef USE_POP
+ { "pop", U_POP },
{ "pops", U_POPS },
-# endif
-#endif
{ "mailto", U_MAILTO },
{ NULL, U_UNKNOWN}
};
static void url_pct_decode (char *s)
{
char *d;
+
+ if (!s)
+ return;
+
for (d = s; *s; s++)
{
if (*s == '%' && s[1] && s[2] &&
char *t;
char *p;
char *path;
-
+
+ ciss->user = NULL;
+ ciss->pass = NULL;
+ ciss->host = NULL;
+ ciss->port = 0;
+
if (strncmp (src, "//", 2))
return src;
src += 2;
-
+
if ((path = strchr (src, '/')))
*path++ = '\0';
{
*p = '\0';
ciss->pass = safe_strdup (p + 1);
+ url_pct_decode (ciss->pass);
}
ciss->user = safe_strdup (src);
+ url_pct_decode (ciss->user);
t++;
}
else
ciss->port = 0;
ciss->host = safe_strdup (t);
+ url_pct_decode (ciss->host);
return path;
}
static void ciss_parse_path (ciss_url_t *ciss, char *src)
{
- ciss->path = src;
+ ciss->path = safe_strdup (src);
url_pct_decode (ciss->path);
}
#ifndef _URL_H
# define _URL_H
-# include "config.h"
-
typedef enum url_scheme
{
U_FILE,
-# ifdef USE_POP
U_POP,
-# endif
-# ifdef USE_IMAP
+ U_POPS,
U_IMAP,
-# endif
-# ifdef USE_SSL
-# ifdef USE_IMAP
U_IMAPS,
-# endif
-# ifdef USE_POP
- U_POPS,
-# endif
-# endif
U_MAILTO,
U_UNKNOWN
}