Commit 0bb93106 authored by Thomas Roessler's avatar Thomas Roessler

IMAP socket moves by Brendan Cully, with a fix from Tommi

Komulainen, and most likely based on input from Vsevolod Voykov
(sp?).
parent 039867ca
......@@ -56,22 +56,21 @@ non_us_sources = pgp.c pgpinvoke.c pgpkey.c pgplib.c sha1dgst.c \
contrib/pgp2.rc contrib/pgp5.rc contrib/gpg.rc \
imap/imap_ssl.c imap/imap_ssl.h README.SSL
EXTRA_mutt_SOURCES = pgp.c pgpinvoke.c pgpkey.c pgplib.c sha1dgst.c \
gnupgparse.c resize.c dotlock.c pop.c remailer.c remailer.h browser.h \
mbyte.h
EXTRA_mutt_SOURCES = account.c mutt_socket.c pop.c pgp.c pgpinvoke.c pgpkey.c \
pgplib.c sha1dgst.c gnupgparse.c resize.c dotlock.c remailer.c \
browser.h mbyte.h remailer.h
EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP TODO configure acconfig.h attach.h \
buffy.h charset.h copy.h dotlock.h functions.h gen_defs \
EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP TODO configure acconfig.h account.h \
attach.h buffy.h charset.h copy.h dotlock.h functions.h gen_defs \
globals.h hash.h history.h init.h keymap.h \
mailbox.h mapping.h mime.h mutt.h mutt_curses.h mutt_menu.h \
mutt_regex.h mx.h pager.h parse.h pgp.h protos.h \
mutt_regex.h mutt_socket.h mx.h pager.h parse.h pgp.h protos.h \
reldate.h rfc1524.h rfc2047.h rfc2231.h rfc822.h sha.h sha_locl.h \
sort.h mime.types VERSION prepare _regex.h OPS.MIX \
README.SECURITY remailer.c remailer.h browser.h \
mbyte.h lib.h extlib.c pgpewrap pgplib.h Muttrc.head Muttrc \
makedoc.c stamp-doc-rc README.SSL README.UPGRADE
mutt_dotlock_SOURCES = mutt_dotlock.c
mutt_dotlock_LDADD = @LIBOBJS@
mutt_dotlock_DEPENDENCIES = @LIBOBJS@
......@@ -80,7 +79,6 @@ pgpring_SOURCES = pgppubring.c pgplib.c lib.c extlib.c sha1dgst.c
pgpring_LDADD = @LIBOBJS@ $(INTLLIBS)
pgpring_DEPENDENCIES = @LIBOBJS@ $(INTLDEPS)
mutt_dotlock.c: dotlock.c
cp $(srcdir)/dotlock.c mutt_dotlock.c
......
......@@ -36,6 +36,10 @@
*/
#undef NFS_ATTRIBUTE_HACK
/* Include code for socket support. Set automatically if you enable pop or
* IMAP */
#undef USE_SOCKET
/* Do you want support for the POP3 protocol? (--enable-pop) */
#undef USE_POP
......
/*
* Copyright (C) 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.
*/
/* remote host account manipulation (POP/IMAP) */
#include "account.h"
#include "mutt.h"
/* mutt_account_match: compare account info (host/port/user) */
int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
{
const char* user = NONULL (Username);
if (a1->type != a2->type)
return 0;
if (mutt_strcasecmp (a1->host, a2->host))
return 0;
if (a1->port != a2->port)
return 0;
#ifdef USE_IMAP
if (a1->type == M_ACCT_TYPE_IMAP && ImapUser)
user = ImapUser;
#endif
#ifdef USE_POP
if (a1->type == M_ACCT_TYPE_POP && PopUser)
user = PopUser;
#endif
if (a1->flags & a2->flags & M_ACCT_USER)
return (!strcmp (a1->user, a2->user));
if (a1->flags & M_ACCT_USER)
return (!strcmp (a1->user, user));
if (a2->flags & M_ACCT_USER)
return (!strcmp (a2->user, user));
return 1;
}
/*
* Copyright (C) 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.
*/
/* remote host account manipulation (POP/IMAP) */
#ifndef _MUTT_ACCOUNT_H_
#define _MUTT_ACCOUNT_H_ 1
/* account types */
enum
{
M_ACCT_TYPE_NONE = 0,
M_ACCT_TYPE_IMAP,
M_ACCT_TYPE_POP
};
/* account flags */
#define M_ACCT_PORT (1<<0)
#define M_ACCT_USER (1<<1)
#define M_ACCT_SSL (1<<2)
#define M_ACCT_CRAM (1<<3)
#define M_ACCT_PASS (1<<4)
typedef struct
{
char user[64];
char pass[32];
char host[128];
unsigned short port;
unsigned char type;
unsigned char flags;
} ACCOUNT;
/* imap_account_match: compare account info (host/port/user) */
int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* m2);
#endif /* _MUTT_ACCOUNT_H_ */
......@@ -527,7 +527,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
{
init_state (&state, NULL);
state.imap_browse = 1;
imap_init_browse (f, &state);
imap_browse (f, &state);
strfcpy (LastDir, state.folder, sizeof (LastDir));
}
else
......@@ -575,7 +575,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
{
init_state (&state, NULL);
state.imap_browse = 1;
imap_init_browse (LastDir, &state);
imap_browse (LastDir, &state);
}
#endif
}
......@@ -715,7 +715,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
{
init_state (&state, NULL);
state.imap_browse = 1;
imap_init_browse (LastDir, &state);
imap_browse (LastDir, &state);
menu->data = state.entry;
}
else
......@@ -879,7 +879,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
destroy_state (&state);
init_state (&state, NULL);
state.imap_browse = 1;
imap_init_browse (LastDir, &state);
imap_browse (LastDir, &state);
menu->data = state.entry;
menu->current = 0;
menu->top = 0;
......@@ -958,7 +958,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
{
init_state (&state, NULL);
state.imap_browse = 1;
imap_init_browse (LastDir, &state);
imap_browse (LastDir, &state);
menu->data = state.entry;
init_menu (&state, menu, title, sizeof (title), buffy);
}
......@@ -1043,7 +1043,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy,
{
init_state (&state, NULL);
state.imap_browse = 1;
imap_init_browse (LastDir, &state);
imap_browse (LastDir, &state);
menu->data = state.entry;
}
#endif
......
......@@ -530,27 +530,41 @@ AC_ARG_WITH(domain, [ --with-domain=DOMAIN Specify your DNS domain name ]
AC_DEFINE_UNQUOTED(DOMAIN, "$withval")
fi])
need_socket="no"
dnl -- socket dependencies --
AC_ARG_ENABLE(pop, [ --enable-pop Enable POP3 support],
[ if test x$enableval = xyes ; then
AC_DEFINE(USE_POP)
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS pop.o"
need_socket="yes"
fi
])
AC_ARG_ENABLE(imap, [ --enable-imap Enable IMAP support],
[ if test x$enableval = xyes ; then
AC_DEFINE(USE_IMAP)
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
LIBIMAP="-Limap -limap"
LIBIMAPDEPS="\$(top_srcdir)/imap/imap.h imap/libimap.a"
need_imap="yes"
need_socket="yes"
fi
])
AM_CONDITIONAL(BUILD_IMAP, test x$need_imap = xyes)
dnl -- end socket dependencies --
if test "$need_socket" = "yes"
then
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
AC_DEFINE(USE_SOCKET)
MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS account.o mutt_socket.o"
fi
dnl -- imap dependencies --
AC_ARG_WITH(gss, [ --with-gss[=DIR] Compile in GSSAPI authentication for IMAP],
[
if test "$need_imap" != "yes"
......@@ -646,6 +660,8 @@ AC_ARG_WITH(ssl, [ --with-ssl[=PFX] Compile in SSL socket support for
])
AM_CONDITIONAL(USE_SSL, test x$need_ssl = xyes)
dnl -- end imap dependencies --
AC_ARG_ENABLE(debug, [ --enable-debug Enable debugging support],
[ if test x$enableval = xyes ; then
AC_DEFINE(DEBUG)
......
......@@ -110,7 +110,7 @@ char *mutt_gettext (const char *message)
orig = gettext (message);
if (debugfile)
dprint (2, (debugfile, "mutt_gettext (`%s'): original gettext returned `%s'\n",
dprint (3, (debugfile, "mutt_gettext (`%s'): original gettext returned `%s'\n",
message, orig));
if (!Messages)
......@@ -119,7 +119,7 @@ char *mutt_gettext (const char *message)
if ((mp = hash_find (Messages, orig)))
{
if (debugfile)
dprint (2, (debugfile, "mutt_gettext: cache hit - key = `%s', data = `%s'\n", orig, mp->data));
dprint (3, (debugfile, "mutt_gettext: cache hit - key = `%s', data = `%s'\n", orig, mp->data));
return mp->data;
}
......@@ -130,7 +130,7 @@ char *mutt_gettext (const char *message)
mutt_convert_string (&mp->data, PoCharset ? PoCharset : "utf-8", MessageCharset);
if (debugfile)
dprint (2, (debugfile, "mutt_gettext: conversion done - src = `%s', res = `%s'\n",
dprint (3, (debugfile, "mutt_gettext: conversion done - src = `%s', res = `%s'\n",
mp->key, mp->data));
hash_insert (Messages, mp->key, mp, 0);
......
......@@ -54,7 +54,6 @@ WHERE char *ImapCRAMKey INITVAL (NULL);
WHERE char *ImapPass INITVAL (NULL);
WHERE short ImapCheckTimeout;
WHERE char *ImapHomeNamespace INITVAL (NULL);
WHERE char *ImapPreconnect INITVAL (NULL);
#endif
WHERE char *InReplyTo;
WHERE char *Inbox;
......@@ -64,6 +63,10 @@ WHERE char *MailcapPath;
WHERE char *Maildir;
WHERE char *MsgFmt;
#ifdef USE_SOCKET
WHERE char *Preconnect INITVAL (NULL);
#endif /* USE_SOCKET */
#ifdef MIXMASTER
WHERE char *Mixmaster;
WHERE char *MixEntryFormat;
......
......@@ -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)
......@@ -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;
......
......@@ -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,
......
......@@ -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);
......
......@@ -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