summaryrefslogtreecommitdiffstats
path: root/imap
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2001-02-15 16:37:25 +0000
committerThomas Roessler <roessler@does-not-exist.org>2001-02-15 16:37:25 +0000
commit9bfbb6b1f09b1ebe255a2f66022d6b3fa9a07aaf (patch)
tree8b4a330e41dea87fba3b91bac367c6ad5476f186 /imap
parent8b0ee07826bafbcd21a514c793d3187787cb36aa (diff)
Brendan Cully's latest STARTTLS patch.
Diffstat (limited to 'imap')
-rw-r--r--imap/browse.c2
-rw-r--r--imap/imap.c27
-rw-r--r--imap/imap.h2
-rw-r--r--imap/util.c236
4 files changed, 167 insertions, 100 deletions
diff --git a/imap/browse.c b/imap/browse.c
index 7a31f63d..1326bd92 100644
--- a/imap/browse.c
+++ b/imap/browse.c
@@ -209,6 +209,8 @@ int imap_browse (char* path, struct browser_state* state)
if (browse_add_list_result (idata, buf, state, 0))
goto fail;
+ mutt_clear_error ();
+
qsort(&(state->entry[nsup]),state->entrylen-nsup,sizeof(state->entry[0]),
(int (*)(const void*,const void*)) compare_names);
if (home_namespace)
diff --git a/imap/imap.c b/imap/imap.c
index 2b479601..ba9d2013 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -332,23 +332,28 @@ int imap_open_connection (IMAP_DATA* idata)
if (imap_check_capabilities (idata))
goto bail;
#if defined(USE_SSL) && !defined(USE_NSS)
- /* Attempt STARTTLS if available. TODO: make STARTTLS configurable. */
+ /* Attempt STARTTLS if available and desired. */
if (mutt_bit_isset (idata->capabilities, STARTTLS))
{
- if ((rc = imap_exec (idata, "STARTTLS", IMAP_CMD_FAIL_OK)) == -1)
+ if ((rc = query_quadoption (OPT_SSLSTARTTLS,
+ _("Secure connection with TLS?"))) == -1)
goto bail;
- if (rc != -2)
- {
- if (mutt_ssl_starttls (idata->conn))
- {
- dprint (1, (debugfile, "imap_open_connection: STARTTLS failed\n"));
+ if (rc == M_YES) {
+ if ((rc = imap_exec (idata, "STARTTLS", IMAP_CMD_FAIL_OK)) == -1)
goto bail;
- }
- else
+ if (rc != -2)
{
- /* RFC 2595 demands we recheck CAPABILITY after TLS is negotiated. */
- if (imap_exec (idata, "CAPABILITY", 0))
+ if (mutt_ssl_starttls (idata->conn))
+ {
+ dprint (1, (debugfile, "imap_open_connection: STARTTLS failed\n"));
goto bail;
+ }
+ else
+ {
+ /* RFC 2595 demands we recheck CAPABILITY after TLS completes. */
+ if (imap_exec (idata, "CAPABILITY", 0))
+ goto bail;
+ }
}
}
}
diff --git a/imap/imap.h b/imap/imap.h
index a89ba032..b05dc182 100644
--- a/imap/imap.h
+++ b/imap/imap.h
@@ -1,5 +1,6 @@
/*
* Copyright (C) 1996-8 Michael R. Elkins <me@cs.hmc.edu>
+ * Copyright (C) 2000-1 Brendan Cully <brendan@kublai.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -60,6 +61,7 @@ void imap_logout_all (void);
/* util.c */
int imap_parse_path (const char* path, IMAP_MBOX* mx);
+void imap_pretty_mailbox (char* path);
int imap_wait_keepalive (pid_t pid);
void imap_keepalive (void);
diff --git a/imap/util.c b/imap/util.c
index c0cfa1d7..e43dfee2 100644
--- a/imap/util.c
+++ b/imap/util.c
@@ -35,6 +35,153 @@
#include <errno.h>
+/* -- public functions -- */
+
+/* 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)
+{
+ char tmp[128];
+ ciss_url_t url;
+ char *c;
+ int n;
+
+ /* Defaults */
+ mx->account.flags = 0;
+ mx->account.port = IMAP_PORT;
+ 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)
+ {
+ 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, "{%128[^}]}", 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, "%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)
+ {
+ 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))
+ mx->account.flags |= M_ACCT_SSL;
+#endif
+
+ if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
+ mx->account.port = IMAP_SSL_PORT;
+
+ return 0;
+}
+
+/* imap_pretty_mailbox: called by mutt_pretty_mailbox to make IMAP paths
+ * look nice. */
+void imap_pretty_mailbox (char* path)
+{
+ IMAP_MBOX home, target;
+ ciss_url_t url;
+ char* delim;
+ int tlen;
+ int hlen = 0;
+ char home_match = 0;
+
+ if (imap_parse_path (path, &target) < 0)
+ return;
+
+ tlen = mutt_strlen (target.mbox);
+ /* check whether we can do '=' substitution */
+ if (! imap_parse_path (Maildir, &home))
+ {
+ hlen = mutt_strlen (home.mbox);
+ if (tlen && mutt_account_match (&home.account, &target.account) &&
+ !mutt_strncmp (home.mbox, target.mbox, hlen))
+ {
+ if (! hlen)
+ home_match = 1;
+ else
+ for (delim = ImapDelimChars; *delim != '\0'; delim++)
+ if (target.mbox[hlen] == *delim)
+ home_match = 1;
+ }
+ FREE (&home.mbox);
+ }
+
+ /* do the '=' substitution */
+ if (home_match) {
+ *path++ = '=';
+ /* copy remaining path, skipping delimiter */
+ if (! hlen)
+ hlen = -1;
+ memcpy (path, target.mbox + hlen + 1, tlen - hlen - 1);
+ path[tlen - hlen - 1] = '\0';
+ }
+ else
+ {
+ mutt_account_tourl (&target.account, &url);
+ url.path = target.mbox;
+ /* FIXME: That hard-coded constant is bogus. But we need the actual
+ * size of the buffer from mutt_pretty_mailbox. And these pretty
+ * operations usually shrink the result. Still... */
+ url_ciss_tostring (&url, path, 1024);
+ }
+
+ FREE (&target.mbox);
+}
+
+/* -- library functions -- */
+
/* imap_continue: display a message and ask the user if she wants to
* go on. */
int imap_continue (const char* msg, const char* resp)
@@ -204,95 +351,6 @@ time_t imap_parse_date (char *s)
return (mutt_mktime (&t, 0) + tz);
}
-/* 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)
-{
- char tmp[128];
- ciss_url_t url;
- char *c;
- int n;
-
- /* Defaults */
- mx->account.flags = 0;
- mx->account.port = IMAP_PORT;
- 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)
- {
- 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, "{%128[^}]}", 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, "%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)
- {
- 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))
- mx->account.flags |= M_ACCT_SSL;
-#endif
-
- if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
- mx->account.port = IMAP_SSL_PORT;
-
- return 0;
-}
-
/* imap_qualify_path: make an absolute IMAP folder target, given IMAP_MBOX
* and relative path. */
void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path)