diff options
-rw-r--r-- | Makefile.am | 14 | ||||
-rw-r--r-- | acconfig.h | 4 | ||||
-rw-r--r-- | account.c | 54 | ||||
-rw-r--r-- | account.h | 52 | ||||
-rw-r--r-- | browser.c | 12 | ||||
-rw-r--r-- | configure.in | 24 | ||||
-rw-r--r-- | gettext.c | 6 | ||||
-rw-r--r-- | globals.h | 5 | ||||
-rw-r--r-- | imap/Makefile.am | 4 | ||||
-rw-r--r-- | imap/auth.c | 44 | ||||
-rw-r--r-- | imap/auth_gss.c | 2 | ||||
-rw-r--r-- | imap/browse.c | 23 | ||||
-rw-r--r-- | imap/imap.c | 120 | ||||
-rw-r--r-- | imap/imap.h | 19 | ||||
-rw-r--r-- | imap/imap_private.h | 22 | ||||
-rw-r--r-- | imap/imap_ssl.c | 11 | ||||
-rw-r--r-- | imap/imap_ssl.h | 6 | ||||
-rw-r--r-- | imap/message.c | 6 | ||||
-rw-r--r-- | imap/util.c | 73 | ||||
-rw-r--r-- | init.c | 1 | ||||
-rw-r--r-- | init.h | 39 | ||||
-rw-r--r-- | mutt_socket.c (renamed from imap/socket.c) | 101 | ||||
-rw-r--r-- | mutt_socket.h (renamed from imap/imap_socket.h) | 24 | ||||
-rw-r--r-- | po/POTFILES.in | 2 |
24 files changed, 398 insertions, 270 deletions
diff --git a/Makefile.am b/Makefile.am index 772e5009..72d9a9d8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/account.c b/account.c new file mode 100644 index 00000000..52bb58a1 --- /dev/null +++ b/account.c @@ -0,0 +1,54 @@ +/* + * 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; +} diff --git a/account.h b/account.h new file mode 100644 index 00000000..20c5e63a --- /dev/null +++ b/account.h @@ -0,0 +1,52 @@ +/* + * 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 diff --git a/configure.in b/configure.in index f816bafc..9954804b 100644 --- a/configure.in +++ b/configure.in @@ -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; 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; |