summaryrefslogtreecommitdiffstats
path: root/imap
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2000-07-19 10:21:54 +0000
committerThomas Roessler <roessler@does-not-exist.org>2000-07-19 10:21:54 +0000
commit0bb931062293d5c81c752f7df8b1426bbab56b9b (patch)
tree1a47e5cca3516249b7c5cfb9aa808fc27945d3c3 /imap
parent039867ca1baed1173c6511e67ba8a108cfcc9730 (diff)
IMAP socket moves by Brendan Cully, with a fix from Tommi
Komulainen, and most likely based on input from Vsevolod Voykov (sp?).
Diffstat (limited to 'imap')
-rw-r--r--imap/Makefile.am4
-rw-r--r--imap/auth.c44
-rw-r--r--imap/auth_gss.c2
-rw-r--r--imap/browse.c23
-rw-r--r--imap/imap.c120
-rw-r--r--imap/imap.h19
-rw-r--r--imap/imap_private.h22
-rw-r--r--imap/imap_socket.h61
-rw-r--r--imap/imap_ssl.c11
-rw-r--r--imap/imap_ssl.h6
-rw-r--r--imap/message.c6
-rw-r--r--imap/socket.c292
-rw-r--r--imap/util.c73
13 files changed, 159 insertions, 524 deletions
diff --git a/imap/Makefile.am b/imap/Makefile.am
index 124893b2..5ff4d388 100644
--- a/imap/Makefile.am
+++ b/imap/Makefile.am
@@ -16,7 +16,7 @@ EXTRA_DIST = BUGS README TODO imap_ssl.c imap_ssl.h auth_gss.c
INCLUDES = -I$(top_srcdir) -I../intl
noinst_LIBRARIES = libimap.a
-noinst_HEADERS = imap_private.h imap_socket.h md5.h message.h $(SSLHEADERS)
+noinst_HEADERS = imap_private.h md5.h message.h $(SSLHEADERS)
libimap_a_SOURCES = auth.c browse.c command.c imap.c imap.h md5c.c message.c \
- socket.c utf7.c util.c $(GSSSOURCES) $(SSLSOURCES)
+ utf7.c util.c $(GSSSOURCES) $(SSLSOURCES)
diff --git a/imap/auth.c b/imap/auth.c
index 77f25c0d..0c857761 100644
--- a/imap/auth.c
+++ b/imap/auth.c
@@ -242,18 +242,20 @@ static int imap_auth_anon (IMAP_DATA* idata)
* Unavailable:
* KERBEROS_V4. Superceded by GSSAPI.
*/
-int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
+int imap_authenticate (IMAP_DATA* idata)
{
char buf[LONG_STRING];
char user[SHORT_STRING], q_user[SHORT_STRING];
char ckey[SHORT_STRING];
char pass[SHORT_STRING], q_pass[SHORT_STRING];
+ CONNECTION* conn = idata->conn;
+
int r = 1;
while (r != 0)
{
- if (! (conn->mx.flags & M_IMAP_USER))
+ if (! (conn->account.flags & M_ACCT_USER))
{
if (!ImapUser)
{
@@ -268,7 +270,7 @@ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
strfcpy (user, ImapUser, sizeof (user));
}
else
- strfcpy (user, conn->mx.user, sizeof (user));
+ strfcpy (user, conn->account.user, sizeof (user));
if (!user[0])
{
@@ -300,13 +302,13 @@ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
/* attempt CRAM-MD5 if available */
if (mutt_bit_isset (idata->capabilities, ACRAM_MD5))
{
- if (!(conn->mx.flags & M_IMAP_CRAM))
+ if (!(conn->account.flags & M_ACCT_CRAM))
{
if (!ImapCRAMKey)
{
ckey[0] = '\0';
snprintf (buf, sizeof (buf), _("CRAM key for %s@%s: "), user,
- conn->mx.host);
+ conn->account.host);
if (mutt_get_field (buf, ckey, sizeof (ckey), M_PASS) != 0)
return -1;
}
@@ -314,7 +316,7 @@ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
strfcpy (ckey, ImapCRAMKey, sizeof (ckey));
}
else
- strfcpy (ckey, conn->mx.pass, sizeof (ckey));
+ strfcpy (ckey, conn->account.pass, sizeof (ckey));
if (*ckey)
{
@@ -322,14 +324,14 @@ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
{
mutt_error _("CRAM-MD5 authentication failed.");
sleep (1);
- if (!(conn->mx.flags & M_IMAP_CRAM))
+ if (!(conn->account.flags & M_ACCT_CRAM))
FREE (&ImapCRAMKey);
- conn->mx.flags &= ~M_IMAP_CRAM;
+ conn->account.flags &= ~M_ACCT_CRAM;
}
else
{
- strfcpy (conn->mx.pass, ckey, sizeof (conn->mx.pass));
- conn->mx.flags |= M_IMAP_CRAM;
+ strfcpy (conn->account.pass, ckey, sizeof (conn->account.pass));
+ conn->account.flags |= M_ACCT_CRAM;
return 0;
}
}
@@ -342,13 +344,13 @@ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
else
dprint (2, (debugfile, "CRAM-MD5 authentication is not available\n"));
- if (! (conn->mx.flags & M_IMAP_PASS))
+ if (! (conn->account.flags & M_ACCT_PASS))
{
if (!ImapPass)
{
pass[0]=0;
snprintf (buf, sizeof (buf), _("Password for %s@%s: "), user,
- conn->mx.host);
+ conn->account.host);
if (mutt_get_field (buf, pass, sizeof (pass), M_PASS) != 0 ||
!pass[0])
return -1;
@@ -357,7 +359,7 @@ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
strfcpy (pass, ImapPass, sizeof (pass));
}
else
- strfcpy (pass, conn->mx.pass, sizeof (pass));
+ strfcpy (pass, conn->account.pass, sizeof (pass));
imap_quote_string (q_user, sizeof (q_user), user);
imap_quote_string (q_pass, sizeof (q_pass), pass);
@@ -387,22 +389,22 @@ int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn)
mutt_error _("Login failed.");
sleep (1);
- if (!(conn->mx.flags & M_IMAP_USER))
+ if (!(conn->account.flags & M_ACCT_USER))
FREE (&ImapUser);
- if (!(conn->mx.flags & M_IMAP_PASS))
+ if (!(conn->account.flags & M_ACCT_PASS))
FREE (&ImapPass);
- conn->mx.flags &= ~M_IMAP_PASS;
+ conn->account.flags &= ~M_ACCT_PASS;
}
else
{
/* If they have a successful login, we may as well cache the
* user/password. */
- if (!(conn->mx.flags & M_IMAP_USER))
- strfcpy (conn->mx.user, user, sizeof (conn->mx.user));
- if (!(conn->mx.flags & M_IMAP_PASS))
- strfcpy (conn->mx.pass, pass, sizeof (conn->mx.pass));
+ if (!(conn->account.flags & M_ACCT_USER))
+ strfcpy (conn->account.user, user, sizeof (conn->account.user));
+ if (!(conn->account.flags & M_ACCT_PASS))
+ strfcpy (conn->account.pass, pass, sizeof (conn->account.pass));
- conn->mx.flags |= (M_IMAP_USER | M_IMAP_PASS);
+ conn->account.flags |= (M_ACCT_USER | M_ACCT_PASS);
}
}
return 0;
diff --git a/imap/auth_gss.c b/imap/auth_gss.c
index effe47dd..48a8ba1f 100644
--- a/imap/auth_gss.c
+++ b/imap/auth_gss.c
@@ -57,7 +57,7 @@ int imap_auth_gss (IMAP_DATA* idata, const char* user)
dprint (2, (debugfile, "Attempting GSS login...\n"));
/* get an IMAP service ticket for the server */
- snprintf (buf1, sizeof (buf1), "imap@%s", idata->conn->mx.host);
+ snprintf (buf1, sizeof (buf1), "imap@%s", idata->conn->account.host);
request_buf.value = buf1;
request_buf.length = strlen (buf1) + 1;
maj_stat = gss_import_name (&min_stat, &request_buf, gss_nt_service_name,
diff --git a/imap/browse.c b/imap/browse.c
index f039fb9d..0f0dfebc 100644
--- a/imap/browse.c
+++ b/imap/browse.c
@@ -26,7 +26,7 @@
#include "imap_private.h"
/* -- forward declarations -- */
-static int browse_add_list_result (CONNECTION* conn, const char* cmd,
+static int browse_add_list_result (IMAP_DATA* idata, const char* cmd,
struct browser_state* state, short isparent);
static void imap_add_folder (char delim, char *folder, int noselect,
int noinferiors, struct browser_state *state, short isparent);
@@ -36,7 +36,7 @@ static int browse_get_namespace (IMAP_DATA *idata, char *nsbuf, int nsblen,
static int browse_verify_namespace (IMAP_DATA* idata,
IMAP_NAMESPACE_INFO* nsi, int nns);
-int imap_init_browse (char *path, struct browser_state *state)
+int imap_browse (char* path, struct browser_state* state)
{
CONNECTION *conn;
IMAP_DATA *idata;
@@ -65,8 +65,8 @@ int imap_init_browse (char *path, struct browser_state *state)
strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", sizeof (list_cmd));
- conn = mutt_socket_find (&mx, 0);
- idata = CONN_DATA;
+ conn = mutt_socket_find (&(mx.account), 0);
+ idata = (IMAP_DATA*) conn->data;
if (!idata || (idata->state == IMAP_DISCONNECTED))
{
@@ -77,7 +77,7 @@ int imap_init_browse (char *path, struct browser_state *state)
conn->data = idata;
idata->conn = conn;
}
- if (imap_open_connection (idata, conn))
+ if (imap_open_connection (idata))
return -1;
}
@@ -138,7 +138,7 @@ int imap_init_browse (char *path, struct browser_state *state)
imap_cmd_start (idata, buf);
do
{
- if (imap_parse_list_response(conn, buf, sizeof(buf), &cur_folder,
+ if (imap_parse_list_response(idata, buf, sizeof(buf), &cur_folder,
&noselect, &noinferiors, &(idata->delim)) != 0)
return -1;
@@ -229,14 +229,14 @@ int imap_init_browse (char *path, struct browser_state *state)
* namespace is not "", so we have to list it explicitly. We ask the
* server to see if it has descendants. */
dprint (4, (debugfile, "imap_init_browse: adding INBOX\n"));
- if (browse_add_list_result (conn, "LIST \"\" \"INBOX\"", state, 0))
+ if (browse_add_list_result (idata, "LIST \"\" \"INBOX\"", state, 0))
return -1;
}
nsup = state->entrylen;
snprintf (buf, sizeof (buf), "%s \"\" \"%s%%\"", list_cmd, mbox);
- if (browse_add_list_result (conn, buf, state, 0))
+ if (browse_add_list_result (idata, buf, state, 0))
return -1;
qsort(&(state->entry[nsup]),state->entrylen-nsup,sizeof(state->entry[0]),
@@ -256,10 +256,9 @@ int imap_init_browse (char *path, struct browser_state *state)
return 0;
}
-static int browse_add_list_result (CONNECTION* conn, const char* cmd,
+static int browse_add_list_result (IMAP_DATA* idata, const char* cmd,
struct browser_state* state, short isparent)
{
- IMAP_DATA* idata = CONN_DATA;
char buf[LONG_STRING];
char *name;
int noselect;
@@ -277,7 +276,7 @@ static int browse_add_list_result (CONNECTION* conn, const char* cmd,
do
{
- if (imap_parse_list_response(conn, buf, sizeof(buf), &name,
+ if (imap_parse_list_response(idata, buf, sizeof(buf), &name,
&noselect, &noinferiors, &(idata->delim)) != 0)
return -1;
@@ -494,7 +493,7 @@ static int browse_verify_namespace (IMAP_DATA* idata,
nsi->home_namespace = 0;
do
{
- if (imap_parse_list_response(idata->conn, buf, sizeof(buf), &name,
+ if (imap_parse_list_response(idata, buf, sizeof(buf), &name,
&(nsi->noselect), &(nsi->noinferiors), &delim) != 0)
return -1;
nsi->listable |= (name != NULL);
diff --git a/imap/imap.c b/imap/imap.c
index e446d03b..f17e19ef 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -37,7 +37,7 @@
#include <sys/stat.h>
/* imap forward declarations */
-static int imap_get_delim (IMAP_DATA *idata, CONNECTION *conn);
+static int imap_get_delim (IMAP_DATA *idata);
static char* imap_get_flags (LIST** hflags, char* s);
static int imap_check_acl (IMAP_DATA *idata);
static int imap_check_capabilities (IMAP_DATA *idata);
@@ -70,6 +70,33 @@ int imap_delete_mailbox (CONTEXT* ctx, char* mailbox)
return 0;
}
+/* imap_logout_all: close all open connections. Quick and dirty until we can
+ * make sure we've got all the context we need. */
+void imap_logout_all (void)
+{
+ CONNECTION* conn;
+ CONNECTION* tmp;
+
+ conn = mutt_socket_head ();
+
+ while (conn)
+ {
+ tmp = conn;
+
+ if (conn->account.type == M_ACCT_TYPE_IMAP && conn->up)
+ {
+ mutt_message (_("Closing connection to %s..."), conn->account.host);
+ imap_logout ((IMAP_DATA*) conn->data);
+ mutt_clear_error ();
+ mutt_socket_close (conn);
+
+ mutt_socket_free (tmp);
+ }
+
+ conn = conn->next;
+ }
+}
+
/* imap_parse_date: date is of the form: DD-MMM-YYYY HH:MM:SS +ZZzz */
time_t imap_parse_date (char *s)
{
@@ -121,7 +148,7 @@ time_t imap_parse_date (char *s)
/* imap_read_literal: read bytes bytes from server into file. Not explicitly
* buffered, relies on FILE buffering. NOTE: strips \r from \r\n.
* Apparently even literals use \r\n-terminated strings ?! */
-int imap_read_literal (FILE* fp, CONNECTION* conn, long bytes)
+int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes)
{
long pos;
char c;
@@ -132,7 +159,7 @@ int imap_read_literal (FILE* fp, CONNECTION* conn, long bytes)
for (pos = 0; pos < bytes; pos++)
{
- if (mutt_socket_readchar (conn, &c) != 1)
+ if (mutt_socket_readchar (idata->conn, &c) != 1)
{
dprint (1, (debugfile, "imap_read_literal: error during read, %ld bytes read\n", pos));
return -1;
@@ -356,7 +383,7 @@ int imap_reopen_mailbox (CONTEXT *ctx, int *index_hint)
return 0;
}
-static int imap_get_delim (IMAP_DATA *idata, CONNECTION *conn)
+static int imap_get_delim (IMAP_DATA *idata)
{
char buf[LONG_STRING];
char *s;
@@ -369,10 +396,8 @@ static int imap_get_delim (IMAP_DATA *idata, CONNECTION *conn)
do
{
- if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
- {
- return (-1);
- }
+ if (mutt_socket_readln (buf, sizeof (buf), idata->conn) < 0)
+ return -1;
if (buf[0] == '*')
{
@@ -388,13 +413,13 @@ static int imap_get_delim (IMAP_DATA *idata, CONNECTION *conn)
}
else
{
- if (conn->data &&
- imap_handle_untagged (idata, buf) != 0)
- return (-1);
+ if (imap_handle_untagged (idata, buf) != 0)
+ return -1;
}
}
}
while ((mutt_strncmp (buf, idata->seq, SEQLEN) != 0));
+
return 0;
}
@@ -433,18 +458,18 @@ static int imap_check_capabilities (IMAP_DATA *idata)
return 0;
}
-int imap_open_connection (IMAP_DATA *idata, CONNECTION *conn)
+int imap_open_connection (IMAP_DATA* idata)
{
char buf[LONG_STRING];
- if (mutt_socket_open (conn) < 0)
+ if (mutt_socket_open (idata->conn) < 0)
return -1;
idata->state = IMAP_CONNECTED;
- if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
+ if (mutt_socket_readln (buf, sizeof (buf), idata->conn) < 0)
{
- mutt_socket_close (conn);
+ mutt_socket_close (idata->conn);
idata->state = IMAP_DISCONNECTED;
return -1;
@@ -453,9 +478,9 @@ int imap_open_connection (IMAP_DATA *idata, CONNECTION *conn)
if (mutt_strncmp ("* OK", buf, 4) == 0)
{
if (imap_check_capabilities(idata) != 0
- || imap_authenticate (idata, conn) != 0)
+ || imap_authenticate (idata) != 0)
{
- mutt_socket_close (conn);
+ mutt_socket_close (idata->conn);
idata->state = IMAP_DISCONNECTED;
return -1;
}
@@ -464,7 +489,7 @@ int imap_open_connection (IMAP_DATA *idata, CONNECTION *conn)
{
if (imap_check_capabilities(idata) != 0)
{
- mutt_socket_close (conn);
+ mutt_socket_close (idata->conn);
idata->state = IMAP_DISCONNECTED;
return -1;
}
@@ -472,14 +497,14 @@ int imap_open_connection (IMAP_DATA *idata, CONNECTION *conn)
else
{
imap_error ("imap_open_connection()", buf);
- mutt_socket_close (conn);
+ mutt_socket_close (idata->conn);
idata->state = IMAP_DISCONNECTED;
return -1;
}
idata->state = IMAP_AUTHENTICATED;
- imap_get_delim (idata, conn);
+ imap_get_delim (idata);
return 0;
}
@@ -540,7 +565,7 @@ static char* imap_get_flags (LIST** hflags, char* s)
return s;
}
-int imap_open_mailbox (CONTEXT *ctx)
+int imap_open_mailbox (CONTEXT* ctx)
{
CONNECTION *conn;
IMAP_DATA *idata;
@@ -556,8 +581,8 @@ int imap_open_mailbox (CONTEXT *ctx)
return -1;
}
- conn = mutt_socket_find (&mx, 0);
- idata = CONN_DATA;
+ conn = mutt_socket_find (&(mx.account), 0);
+ idata = (IMAP_DATA*) conn->data;
if (!idata || (idata->state != IMAP_AUTHENTICATED))
{
@@ -567,11 +592,11 @@ int imap_open_mailbox (CONTEXT *ctx)
/* We need to create a new connection, the current one isn't useful */
idata = safe_calloc (1, sizeof (IMAP_DATA));
- conn = mutt_socket_find (&mx, 1);
+ conn = mutt_socket_find (&(mx.account), 1);
conn->data = idata;
idata->conn = conn;
}
- if (imap_open_connection (idata, conn))
+ if (imap_open_connection (idata))
return -1;
}
ctx->data = (void *) idata;
@@ -727,18 +752,18 @@ int imap_open_mailbox (CONTEXT *ctx)
int imap_select_mailbox (CONTEXT* ctx, const char* path)
{
IMAP_DATA* idata;
- CONNECTION* conn;
char curpath[LONG_STRING];
IMAP_MBOX mx;
+ idata = CTX_DATA;
+
strfcpy (curpath, path, sizeof (curpath));
/* check that the target folder makes sense */
if (imap_parse_path (curpath, &mx))
return -1;
/* and that it's on the same server as the current folder */
- conn = mutt_socket_find (&mx, 0);
- if (!CTX_DATA || !CONN_DATA || (CTX_DATA->conn != CONN_DATA->conn))
+ if (!mutt_account_match (&(mx.account), &(idata->conn->account)))
{
dprint(2, (debugfile,
"imap_select_mailbox: source server is not target server\n"));
@@ -767,12 +792,12 @@ int imap_open_mailbox_append (CONTEXT *ctx)
IMAP_MBOX mx;
if (imap_parse_path (ctx->path, &mx))
- return (-1);
+ return -1;
ctx->magic = M_IMAP;
- conn = mutt_socket_find (&mx, 0);
- idata = CONN_DATA;
+ conn = mutt_socket_find (&(mx.account), 0);
+ idata = (IMAP_DATA*) conn->data;
if (!idata || (idata->state == IMAP_DISCONNECTED))
{
@@ -783,8 +808,8 @@ int imap_open_mailbox_append (CONTEXT *ctx)
conn->data = idata;
idata->conn = conn;
}
- if (imap_open_connection (idata, conn))
- return (-1);
+ if (imap_open_connection (idata))
+ return -1;
}
ctx->data = (void *) idata;
@@ -1194,7 +1219,7 @@ int imap_check_mailbox (CONTEXT *ctx, int *index_hint)
/* returns count of recent messages if new = 1, else count of total messages.
* (useful for at least postponed function)
* Question of taste: use RECENT or UNSEEN for new? */
-int imap_mailbox_check (char *path, int new)
+int imap_mailbox_check (char* path, int new)
{
CONNECTION *conn;
IMAP_DATA *idata;
@@ -1208,8 +1233,8 @@ int imap_mailbox_check (char *path, int new)
if (imap_parse_path (path, &mx))
return -1;
- conn = mutt_socket_find (&mx, 0);
- idata = CONN_DATA;
+ conn = mutt_socket_find (&(mx.account), 0);
+ idata = (IMAP_DATA*) conn->data;
if (!idata || (idata->state == IMAP_DISCONNECTED))
{
@@ -1224,7 +1249,7 @@ int imap_mailbox_check (char *path, int new)
conn->data = idata;
idata->conn = conn;
}
- if (imap_open_connection (idata, conn))
+ if (imap_open_connection (idata))
return -1;
}
@@ -1301,16 +1326,15 @@ int imap_mailbox_check (char *path, int new)
return msgcount;
}
-int imap_parse_list_response(CONNECTION *conn, char *buf, int buflen,
+int imap_parse_list_response(IMAP_DATA* idata, char *buf, int buflen,
char **name, int *noselect, int *noinferiors, char *delim)
{
- IMAP_DATA *idata = CONN_DATA;
char *s;
long bytes;
*name = NULL;
- if (mutt_socket_readln (buf, buflen, conn) < 0)
+ if (mutt_socket_readln (buf, buflen, idata->conn) < 0)
return -1;
if (buf[0] == '*')
@@ -1358,7 +1382,7 @@ int imap_parse_list_response(CONNECTION *conn, char *buf, int buflen,
if (imap_get_literal_count(buf, &bytes) < 0)
return -1;
- len = mutt_socket_readln (buf, buflen, conn);
+ len = mutt_socket_readln (buf, buflen, idata->conn);
if (len < 0)
return -1;
*name = buf;
@@ -1385,10 +1409,10 @@ int imap_subscribe (char *path, int subscribe)
IMAP_MBOX mx;
if (imap_parse_path (path, &mx))
- return (-1);
+ return -1;
- conn = mutt_socket_find (&mx, 0);
- idata = CONN_DATA;
+ conn = mutt_socket_find (&(mx.account), 0);
+ idata = (IMAP_DATA*) conn->data;
if (!idata || (idata->state == IMAP_DISCONNECTED))
{
@@ -1399,7 +1423,7 @@ int imap_subscribe (char *path, int subscribe)
conn->data = idata;
idata->conn = conn;
}
- if (imap_open_connection (idata, conn))
+ if (imap_open_connection (idata))
return -1;
}
@@ -1442,8 +1466,8 @@ int imap_complete(char* dest, size_t dlen, char* path) {
return -1;
}
- conn = mutt_socket_find (&mx, 0);
- idata = CONN_DATA;
+ conn = mutt_socket_find (&(mx.account), 0);
+ idata = (IMAP_DATA*) conn->data;
/* don't open a new socket just for completion */
if (!idata)
@@ -1470,7 +1494,7 @@ int imap_complete(char* dest, size_t dlen, char* path) {
strfcpy (completion, mx.mbox, sizeof(completion));
do
{
- if (imap_parse_list_response(conn, buf, sizeof(buf), &list_word,
+ if (imap_parse_list_response(idata, buf, sizeof(buf), &list_word,
&noselect, &noinferiors, &delim))
break;
diff --git a/imap/imap.h b/imap/imap.h
index 2b0b5b74..c4997a10 100644
--- a/imap/imap.h
+++ b/imap/imap.h
@@ -19,22 +19,17 @@
#ifndef _IMAP_H
#define _IMAP_H 1
+#include "account.h"
#include "browser.h"
#include "mailbox.h"
+/* -- data structures -- */
typedef struct
{
- char user[64];
- char pass[32];
- char host[128];
- int port;
- char type[16];
- int socktype;
- char *mbox;
- int flags;
+ ACCOUNT account;
+ char* mbox;
} IMAP_MBOX;
-
/* imap.c */
int imap_check_mailbox (CONTEXT *ctx, int *index_hint);
int imap_create_mailbox (CONTEXT* idata, char* mailbox);
@@ -54,7 +49,7 @@ void imap_allow_reopen (CONTEXT *ctx);
void imap_disallow_reopen (CONTEXT *ctx);
/* browse.c */
-int imap_init_browse (char *path, struct browser_state *state);
+int imap_browse (char* path, struct browser_state* state);
/* message.c */
int imap_append_message (CONTEXT* ctx, MESSAGE* msg);
@@ -65,8 +60,8 @@ int imap_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno);
void imap_logout_all (void);
/* util.c */
-int imap_parse_path (const char* path, IMAP_MBOX *mx);
-void imap_qualify_path (char* dest, size_t len, const IMAP_MBOX *mx,
+int imap_parse_path (const char* path, IMAP_MBOX* mx);
+void imap_qualify_path (char* dest, size_t len, const IMAP_MBOX* mx,
const char* path, const char* name);
int imap_wait_keepalive (pid_t pid);
diff --git a/imap/imap_private.h b/imap/imap_private.h
index ea55e25b..f2639ab8 100644
--- a/imap/imap_private.h
+++ b/imap/imap_private.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2000 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
@@ -21,7 +21,7 @@
#define _IMAP_PRIVATE_H 1
#include "imap.h"
-#include "imap_socket.h"
+#include "mutt_socket.h"
/* -- symbols -- */
#define IMAP_PORT 143
@@ -37,12 +37,6 @@
#define SEQLEN 5
-#define M_IMAP_USER (1<<0)
-#define M_IMAP_PORT (1<<1)
-#define M_IMAP_TYPE (1<<2)
-#define M_IMAP_PASS (1<<3)
-#define M_IMAP_CRAM (1<<4)
-
#define IMAP_REOPEN_ALLOW (1<<0)
#define IMAP_REOPEN_PENDING (1<<1)
#define IMAP_NEWMAIL_PENDING (1<<2)
@@ -166,22 +160,21 @@ typedef struct
/* -- macros -- */
#define CTX_DATA ((IMAP_DATA *) ctx->data)
-#define CONN_DATA ((IMAP_DATA *) conn->data)
/* -- private IMAP functions -- */
/* imap.c */
int imap_make_msg_set (char* buf, size_t buflen, CONTEXT* ctx, int flag,
int changed);
-int imap_open_connection (IMAP_DATA* idata, CONNECTION* conn);
+int imap_open_connection (IMAP_DATA* idata);
time_t imap_parse_date (char* s);
-int imap_parse_list_response(CONNECTION* conn, char* buf, int buflen,
+int imap_parse_list_response(IMAP_DATA* idata, char* buf, int buflen,
char** name, int* noselect, int* noinferiors, char* delim);
-int imap_read_literal (FILE* fp, CONNECTION* conn, long bytes);
+int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes);
int imap_reopen_mailbox (CONTEXT *ctx, int *index_hint);
-void imap_logout (IMAP_DATA* conn);
+void imap_logout (IMAP_DATA* idata);
/* auth.c */
-int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn);
+int imap_authenticate (IMAP_DATA* idata);
/* command.c */
void imap_cmd_start (IMAP_DATA* idata, const char* cmd);
@@ -197,7 +190,6 @@ void imap_free_header_data (void** data);
int imap_read_headers (CONTEXT* ctx, int msgbegin, int msgend);
/* util.c */
-int imap_account_match (const IMAP_MBOX* m1, const IMAP_MBOX* m2);
int imap_continue (const char* msg, const char* resp);
void imap_error (const char* where, const char* msg);
char* imap_fix_path (IMAP_DATA* idata, char* mailbox, char* path,
diff --git a/imap/imap_socket.h b/imap/imap_socket.h
deleted file mode 100644
index a5145427..00000000
--- a/imap/imap_socket.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 1998 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999-2000 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- */
-
-#ifndef _IMAP_SOCKET_H_
-#define _IMAP_SOCKET_H_ 1
-
-typedef struct _connection
-{
- IMAP_MBOX mx;
- char inbuf[LONG_STRING];
- int bufpos;
-
- int fd;
- int available;
- void *data;
-
- struct _connection *next;
-
- void *sockdata;
- int (*read) (struct _connection *conn);
- int (*write) (struct _connection *conn, const char *buf);
- int (*open) (struct _connection *conn);
- int (*close) (struct _connection *conn);
-
- /* status bits */
-
- int up : 1; /* is the connection up? */
-} CONNECTION;
-
-int mutt_socket_open (CONNECTION* conn);
-int mutt_socket_close (CONNECTION* conn);
-int mutt_socket_readchar (CONNECTION *conn, char *c);
-#define mutt_socket_readln(A,B,C) mutt_socket_readln_d(A,B,C,IMAP_LOG_CMD)
-int mutt_socket_readln_d (char *buf, size_t buflen, CONNECTION *conn, int dbg);
-#define mutt_socket_write(A,B) mutt_socket_write_d(A,B,IMAP_LOG_CMD);
-int mutt_socket_write_d (CONNECTION *conn, const char *buf, int dbg);
-
-CONNECTION* mutt_socket_find (const IMAP_MBOX* mx, int newconn);
-
-int raw_socket_read (CONNECTION *conn);
-int raw_socket_write (CONNECTION *conn, const char *buf);
-int raw_socket_open (CONNECTION *conn);
-int raw_socket_close (CONNECTION *conn);
-
-#endif /* _IMAP_SOCKET_H_ */
diff --git a/imap/imap_ssl.c b/imap/imap_ssl.c
index a805c331..1a97499e 100644
--- a/imap/imap_ssl.c
+++ b/imap/imap_ssl.c
@@ -31,7 +31,7 @@
#include "mutt.h"
#include "imap.h"
#include "imap_private.h"
-#include "imap_socket.h"
+#include "mutt_socket.h"
#include "mutt_menu.h"
#include "mutt_curses.h"
#include "imap_ssl.h"
@@ -144,12 +144,11 @@ static int add_entropy (const char *file)
return n;
}
-void imap_set_ssl (IMAP_MBOX *mx)
+void imap_set_ssl (ACCOUNT* account)
{
- if (! (mx->flags & M_IMAP_PORT))
- mx->port = IMAP_SSL_PORT;
- mx->socktype = M_NEW_SSL_SOCKET;
- mx->flags |= M_IMAP_TYPE;
+ if (! (account->flags & M_ACCT_PORT))
+ account->port = IMAP_SSL_PORT;
+ account->flags |= M_ACCT_SSL;
}
static int ssl_socket_open_err (CONNECTION *conn)
diff --git a/imap/imap_ssl.h b/imap/imap_ssl.h
index 4ee7062d..8c8ec747 100644
--- a/imap/imap_ssl.h
+++ b/imap/imap_ssl.h
@@ -19,10 +19,12 @@
#ifndef _MUTT_SSL_H_
#define _MUTT_SSL_H_ 1
+#include "mutt_socket.h"
+
extern char *SslCertFile;
extern char *SslEntropyFile;
extern int ssl_socket_setup (CONNECTION *conn);
-extern void imap_set_ssl (IMAP_MBOX *mx);
+extern void imap_set_ssl (ACCOUNT* account);
-#endif
+#endif /* _MUTT_SSL_H_ */
diff --git a/imap/message.c b/imap/message.c
index 72574b4d..954a1d67 100644
--- a/imap/message.c
+++ b/imap/message.c
@@ -261,7 +261,7 @@ int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno)
imap_error ("imap_fetch_message()", buf);
goto bail;
}
- if (imap_read_literal (msg->fp, CTX_DATA->conn, bytes) < 0)
+ if (imap_read_literal (msg->fp, CTX_DATA, bytes) < 0)
goto bail;
/* pick up trailing line */
if (mutt_socket_readln (buf, sizeof (buf), CTX_DATA->conn) < 0)
@@ -499,7 +499,7 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete)
}
/* check that the save-to folder is in the same account */
- if (!imap_account_match (&(CTX_DATA->conn->mx), &mx))
+ if (!mutt_account_match (&(CTX_DATA->conn->account), &(mx.account)))
{
dprint (3, (debugfile, "imap_copy_message: %s not same server as %s\n",
dest, ctx->path));
@@ -647,7 +647,7 @@ static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp)
if (imap_get_literal_count (buf, &bytes) < 0)
return rc;
- imap_read_literal (fp, CTX_DATA->conn, bytes);
+ imap_read_literal (fp, CTX_DATA, bytes);
/* we may have other fields of the FETCH _after_ the literal
* (eg Domino puts FLAGS here). Nothing wrong with that, either.
diff --git a/imap/socket.c b/imap/socket.c
deleted file mode 100644
index b70fc698..00000000
--- a/imap/socket.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright (C) 1998 Michael R. Elkins <me@cs.hmc.edu>
- * Copyright (C) 1999-2000 Brendan Cully <brendan@kublai.com>
- * Copyright (C) 1999-2000 Tommi Komulainen <Tommi.Komulainen@iki.fi>
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- */
-
-#include "mutt.h"
-#include "globals.h"
-#include "imap.h"
-#include "imap_socket.h"
-#include "imap_private.h"
-#ifdef USE_SSL
-#include "imap_ssl.h"
-#endif
-
-#include <unistd.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <string.h>
-
-/* support for multiple socket connections */
-static CONNECTION *Connections = NULL;
-
-/* forward declarations */
-static int socket_connect (CONNECTION* conn, struct sockaddr_in sin,
- int verbose);
-static CONNECTION* socket_new_conn ();
-
-/* Wrappers */
-int mutt_socket_open (CONNECTION* conn)
-{
- int rc;
-
- rc = conn->open (conn);
- if (!rc)
- conn->up = 1;
-
- return rc;
-}
-
-int mutt_socket_close (CONNECTION* conn)
-{
- conn->up = 0;
-
- return conn->close (conn);
-}
-
-int mutt_socket_write_d (CONNECTION *conn, const char *buf, int dbg)
-{
- dprint (dbg, (debugfile,"> %s", buf));
-
- return conn->write (conn, buf);
-}
-
-/* simple read buffering to speed things up. */
-int mutt_socket_readchar (CONNECTION *conn, char *c)
-{
- if (conn->bufpos >= conn->available)
- {
- conn->available = conn->read (conn);
- conn->bufpos = 0;
- if (conn->available <= 0)
- return conn->available; /* returns 0 for EOF or -1 for other error */
- }
- *c = conn->inbuf[conn->bufpos];
- conn->bufpos++;
- return 1;
-}
-
-int mutt_socket_readln_d (char* buf, size_t buflen, CONNECTION* conn, int dbg)
-{
- char ch;
- int i;
-
- for (i = 0; i < buflen-1; i++)
- {
- if (mutt_socket_readchar (conn, &ch)