Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Wed, 7 Sep 2005 17:30:48 +0000 (17:30 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Wed, 7 Sep 2005 17:30:48 +0000 (17:30 +0000)
- remove SASL 1.x support as nobody requested to keep it

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@483 e385b8ad-14ed-0310-8656-cc95a2468c6d

12 files changed:
ChangeLog
UPGRADING
VERSION.svn
configure.in
curs_main.c
imap/auth_sasl.c
init.h
main.c
mutt_sasl.c
mutt_sasl.h
pattern.c
pop/pop_auth.c

index b8597a4..68ecb86 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 Changes specific to mutt-ng:
 
 Changes specific to mutt-ng:
 
+2005-09-07:
+  * Mutt-ng no longer contains support for SASL 1.x.
+
 2005-08-29:
   * Mutt-ng now can limit the number of headers to show if
     $edit_headers is set via $editor_headers
 2005-08-29:
   * Mutt-ng now can limit the number of headers to show if
     $edit_headers is set via $editor_headers
index faeb179..650a06d 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -12,6 +12,8 @@ sources of information.
 
 2005-09-07:
 
 
 2005-09-07:
 
+  SASL 1.x support has been removed.
+
   All patterns may be prefixed with = instead of ~ to enable
   string search instead of regular expression match.
 
   All patterns may be prefixed with = instead of ~ to enable
   string search instead of regular expression match.
 
index b283aee..1448fd8 100644 (file)
@@ -1 +1 @@
-482
+483
index 59cf6bf..c0981e0 100644 (file)
@@ -628,36 +628,6 @@ fi
 
 AM_CONDITIONAL(USE_SSL, test x$need_ssl = xyes)
 
 
 AM_CONDITIONAL(USE_SSL, test x$need_ssl = xyes)
 
-AC_ARG_WITH(sasl, AC_HELP_STRING([--with-sasl[=PFX]], [Use Cyrus SASL library for POP/IMAP authentication]),
-        [
-        if test "$with_sasl" != "no" -a "$need_imap" != "yes" -a "$need_pop" != "yes"
-        then
-          AC_MSG_ERROR([SASL support is only useful with POP or IMAP support])
-        fi
-
-        if test "$with_sasl" != "no"
-        then
-          if test "$with_sasl" != "yes"
-          then
-            CPPFLAGS="$CPPFLAGS -I$with_sasl/include"
-            LDFLAGS="$LDFLAGS -L$with_sasl/lib"
-          fi
-
-          saved_LIBS="$LIBS"
-
-          AC_CHECK_LIB(sasl, sasl_client_init,,
-            AC_MSG_ERROR([could not find libsasl]),)
-
-          MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS mutt_sasl.o"
-          MUTTLIBS="$MUTTLIBS -lsasl"
-          LIBS="$saved_LIBS"
-          AC_DEFINE(USE_SASL,1,
-                  [ Define if want to use the Cyrus SASL library for POP/IMAP authentication. ])
-          need_sasl=yes
-        fi
-        ])
-AM_CONDITIONAL(USE_SASL, test x$need_sasl = xyes)
-
 AC_ARG_WITH(sasl2, AC_HELP_STRING([--with-sasl2[=PFX]], [Use Cyrus SASL library version 2 for POP/IMAP authentication]),
         [
         if test "$with_sasl2" != "no" -a "$need_imap" != "yes" -a "$need_pop" != "yes"
 AC_ARG_WITH(sasl2, AC_HELP_STRING([--with-sasl2[=PFX]], [Use Cyrus SASL library version 2 for POP/IMAP authentication]),
         [
         if test "$with_sasl2" != "no" -a "$need_imap" != "yes" -a "$need_pop" != "yes"
@@ -681,8 +651,6 @@ AC_ARG_WITH(sasl2, AC_HELP_STRING([--with-sasl2[=PFX]], [Use Cyrus SASL library
           MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS mutt_sasl.o"
           MUTTLIBS="$MUTTLIBS -lsasl2"
           LIBS="$saved_LIBS"
           MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS mutt_sasl.o"
           MUTTLIBS="$MUTTLIBS -lsasl2"
           LIBS="$saved_LIBS"
-          AC_DEFINE(USE_SASL,1,
-                  [ Define if want to use the Cyrus SASL library for POP/IMAP authentication. ])
           AC_DEFINE(USE_SASL2,1,
                   [ Define if want to use version 2 of the Cyrus SASL library. ])
           need_sasl=yes
           AC_DEFINE(USE_SASL2,1,
                   [ Define if want to use version 2 of the Cyrus SASL library. ])
           need_sasl=yes
index 0222a91..09f28a1 100644 (file)
@@ -2355,7 +2355,7 @@ int mutt_index_menu (void)
   /* Close all open NNTP connections */
     nntp_logout_all ();
 #endif
   /* Close all open NNTP connections */
     nntp_logout_all ();
 #endif
-#if defined (USE_SASL) || defined (USE_SASL2)
+#ifdef USE_SASL
     mutt_sasl_done ();
 #endif
   }
     mutt_sasl_done ();
 #endif
   }
index fa1714f..88001d4 100644 (file)
 #include "lib/intl.h"
 #include "lib/debug.h"
 
 #include "lib/intl.h"
 #include "lib/debug.h"
 
-#ifdef USE_SASL2
+#ifdef USE_SASL
 #include <sasl/sasl.h>
 #include <sasl/saslutil.h>
 #include <sasl/sasl.h>
 #include <sasl/saslutil.h>
-#else
-#include <sasl.h>
-#include <saslutil.h>
 #endif
 
 /* imap_auth_sasl: Default authenticator if available. */
 #endif
 
 /* imap_auth_sasl: Default authenticator if available. */
@@ -40,10 +37,8 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method)
   char buf[HUGE_STRING];
   const char *mech;
 
   char buf[HUGE_STRING];
   const char *mech;
 
-#ifdef USE_SASL2
+#ifdef USE_SASL
   const char *pc = NULL;
   const char *pc = NULL;
-#else
-  char *pc = NULL;
 #endif
   unsigned int len, olen;
   unsigned char client_start;
 #endif
   unsigned int len, olen;
   unsigned char client_start;
@@ -70,24 +65,17 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method)
     if (mutt_bit_isset (idata->capabilities, AUTH_ANON) &&
         (!idata->conn->account.user[0] ||
          !ascii_strncmp (idata->conn->account.user, "anonymous", 9)))
     if (mutt_bit_isset (idata->capabilities, AUTH_ANON) &&
         (!idata->conn->account.user[0] ||
          !ascii_strncmp (idata->conn->account.user, "anonymous", 9)))
-#ifdef USE_SASL2
+#ifdef USE_SASL
       rc = sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, &pc, &olen,
                               &mech);
       rc = sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, &pc, &olen,
                               &mech);
-#else
-      rc =
-        sasl_client_start (saslconn, "AUTH=ANONYMOUS", NULL, NULL, &pc, &olen,
-                           &mech);
 #endif
   }
 
   if (rc != SASL_OK && rc != SASL_CONTINUE)
     do {
 #endif
   }
 
   if (rc != SASL_OK && rc != SASL_CONTINUE)
     do {
-#ifdef USE_SASL2
+#ifdef USE_SASL
       rc = sasl_client_start (saslconn, method, &interaction,
                               &pc, &olen, &mech);
       rc = sasl_client_start (saslconn, method, &interaction,
                               &pc, &olen, &mech);
-#else
-      rc = sasl_client_start (saslconn, method, NULL, &interaction,
-                              &pc, &olen, &mech);
 #endif
       if (rc == SASL_INTERACT)
         mutt_sasl_interact (interaction);
 #endif
       if (rc == SASL_INTERACT)
         mutt_sasl_interact (interaction);
@@ -128,12 +116,10 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method)
       goto bail;
 
     if (irc == IMAP_CMD_RESPOND) {
       goto bail;
 
     if (irc == IMAP_CMD_RESPOND) {
-#ifdef USE_SASL2
+#ifdef USE_SASL
       if (sasl_decode64
           (idata->cmd.buf + 2, str_len (idata->cmd.buf + 2), buf,
            LONG_STRING - 1,
       if (sasl_decode64
           (idata->cmd.buf + 2, str_len (idata->cmd.buf + 2), buf,
            LONG_STRING - 1,
-#else
-      if (sasl_decode64 (idata->cmd.buf + 2, str_len (idata->cmd.buf + 2), buf,
 #endif
                          &len) != SASL_OK) {
         debug_print (1, ("error base64-decoding server response.\n"));
 #endif
                          &len) != SASL_OK) {
         debug_print (1, ("error base64-decoding server response.\n"));
@@ -164,7 +150,7 @@ imap_auth_res_t imap_auth_sasl (IMAP_DATA * idata, const char *method)
 
       /* sasl_client_st(art|ep) allocate pc with malloc, expect me to 
        * free it */
 
       /* sasl_client_st(art|ep) allocate pc with malloc, expect me to 
        * free it */
-#ifndef USE_SASL2
+#ifndef USE_SASL
       mem_free (&pc);
 #endif
     }
       mem_free (&pc);
 #endif
     }
diff --git a/init.h b/init.h
index be6a7bb..d2816e4 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3868,9 +3868,6 @@ static const char* Features[] = {
 #ifdef USE_SASL
   "sasl",
 #endif
 #ifdef USE_SASL
   "sasl",
 #endif
-#ifdef USE_SASL2
-  "sasl2",
-#endif
 #ifdef USE_LIBESMTP
   "libesmtp",
 #endif
 #ifdef USE_LIBESMTP
   "libesmtp",
 #endif
diff --git a/main.c b/main.c
index d7c9674..41899eb 100644 (file)
--- a/main.c
+++ b/main.c
@@ -322,11 +322,6 @@ static void show_version (void)
 #else
          "-USE_SASL  "
 #endif
 #else
          "-USE_SASL  "
 #endif
-#ifdef USE_SASL2
-         "+USE_SASL2  "
-#else
-         "-USE_SASL2  "
-#endif
 #ifdef USE_LIBESMTP
          "+USE_LIBESMTP  "
 #else
 #ifdef USE_LIBESMTP
          "+USE_LIBESMTP  "
 #else
index 9fd1cdd..c93413d 100644 (file)
 #include "lib/mem.h"
 #include "lib/debug.h"
 
 #include "lib/mem.h"
 #include "lib/debug.h"
 
-#ifdef USE_SASL2
 #include <errno.h>
 #include <netdb.h>
 #include <sasl/sasl.h>
 #include <errno.h>
 #include <netdb.h>
 #include <sasl/sasl.h>
-#else
-#include <sasl.h>
-#endif
+
 #include <sys/socket.h>
 #include <netinet/in.h>
 
 #include <sys/socket.h>
 #include <netinet/in.h>
 
-#ifdef USE_SASL2
 static int getnameinfo_err (int ret)
 {
   int err;
 static int getnameinfo_err (int ret)
 {
   int err;
@@ -80,9 +76,7 @@ static int getnameinfo_err (int ret)
  * a protection buffer. */
 #define M_SASL_MAXBUF 65536
 
  * a protection buffer. */
 #define M_SASL_MAXBUF 65536
 
-#ifdef USE_SASL2
 #define IP_PORT_BUFLEN 1024
 #define IP_PORT_BUFLEN 1024
-#endif
 
 static sasl_callback_t mutt_sasl_callbacks[5];
 
 
 static sasl_callback_t mutt_sasl_callbacks[5];
 
@@ -103,7 +97,6 @@ static int mutt_sasl_conn_read (CONNECTION * conn, char *buf, size_t len);
 static int mutt_sasl_conn_write (CONNECTION * conn, const char *buf,
                                  size_t count);
 
 static int mutt_sasl_conn_write (CONNECTION * conn, const char *buf,
                                  size_t count);
 
-#ifdef USE_SASL2
 /* utility function, stolen from sasl2 sample code */
 static int iptostring (const struct sockaddr *addr, socklen_t addrlen,
                        char *out, unsigned outlen)
 /* utility function, stolen from sasl2 sample code */
 static int iptostring (const struct sockaddr *addr, socklen_t addrlen,
                        char *out, unsigned outlen)
@@ -172,13 +165,9 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn)
 {
   sasl_security_properties_t secprops;
 
 {
   sasl_security_properties_t secprops;
 
-#ifdef USE_SASL2
   struct sockaddr_storage local, remote;
   socklen_t size;
   char iplocalport[IP_PORT_BUFLEN], ipremoteport[IP_PORT_BUFLEN];
   struct sockaddr_storage local, remote;
   socklen_t size;
   char iplocalport[IP_PORT_BUFLEN], ipremoteport[IP_PORT_BUFLEN];
-#else
-  sasl_external_properties_t extprops;
-#endif
   const char *service;
   int rc;
 
   const char *service;
   int rc;
 
@@ -197,7 +186,6 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn)
     return -1;
   }
 
     return -1;
   }
 
-#ifdef USE_SASL2
   size = sizeof (local);
   if (getsockname (conn->fd, (struct sockaddr *) &local, &size)) {
     debug_print (1, ("getsockname for local failed\n"));
   size = sizeof (local);
   if (getsockname (conn->fd, (struct sockaddr *) &local, &size)) {
     debug_print (1, ("getsockname for local failed\n"));
@@ -230,12 +218,6 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn)
     sasl_client_new (service, conn->account.host, iplocalport, ipremoteport,
                      mutt_sasl_get_callbacks (&conn->account), 0, saslconn);
 
     sasl_client_new (service, conn->account.host, iplocalport, ipremoteport,
                      mutt_sasl_get_callbacks (&conn->account), 0, saslconn);
 
-#else
-  rc = sasl_client_new (service, conn->account.host,
-                        mutt_sasl_get_callbacks (&conn->account),
-                        SASL_SECURITY_LAYER, saslconn);
-#endif
-
   if (rc != SASL_OK) {
     debug_print (1, ("Error allocating SASL connection\n"));
     return -1;
   if (rc != SASL_OK) {
     debug_print (1, ("Error allocating SASL connection\n"));
     return -1;
@@ -245,7 +227,6 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn)
   /* Do we need to fail if this fails? I would assume having these unset
    * would just disable KRB4. Who wrote this code?
    */
   /* Do we need to fail if this fails? I would assume having these unset
    * would just disable KRB4. Who wrote this code?
    */
-#ifndef USE_SASL2               /* with SASLv2 this all happens in sasl_client_new */
   {
     struct sockaddr_in local, remote;
     socklen_t size;
   {
     struct sockaddr_in local, remote;
     socklen_t size;
@@ -272,7 +253,6 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn)
     }
 #endif
   }
     }
 #endif
   }
-#endif
 
   /* set security properties. We use NOPLAINTEXT globally, since we can
    * just fall back to LOGIN in the IMAP case anyway. If that doesn't
 
   /* set security properties. We use NOPLAINTEXT globally, since we can
    * just fall back to LOGIN in the IMAP case anyway. If that doesn't
@@ -289,27 +269,18 @@ int mutt_sasl_client_new (CONNECTION * conn, sasl_conn_t ** saslconn)
   }
 
   if (conn->ssf) {
   }
 
   if (conn->ssf) {
-#ifdef USE_SASL2                /* I'm not sure this actually has an effect, at least with SASLv2 */
     debug_print (2, ("External SSF: %d\n", conn->ssf));
     if (sasl_setprop (*saslconn, SASL_SSF_EXTERNAL, &(conn->ssf)) != SASL_OK)
     debug_print (2, ("External SSF: %d\n", conn->ssf));
     if (sasl_setprop (*saslconn, SASL_SSF_EXTERNAL, &(conn->ssf)) != SASL_OK)
-#else
-    memset (&extprops, 0, sizeof (extprops));
-    extprops.ssf = conn->ssf;
-    debug_print (2, ("External SSF: %d\n", extprops.ssf));
-    if (sasl_setprop (*saslconn, SASL_SSF_EXTERNAL, &extprops) != SASL_OK)
-#endif
     {
       debug_print (1, ("Error setting external properties\n"));
       return -1;
     }
     {
       debug_print (1, ("Error setting external properties\n"));
       return -1;
     }
-#ifdef USE_SASL2
     debug_print (2, ("External authentication name: %s\n", conn->account.user));
     if (sasl_setprop (*saslconn, SASL_AUTH_EXTERNAL, conn->account.user) !=
         SASL_OK) {
       debug_print (1, ("Error setting external properties\n"));
       return -1;
     }
     debug_print (2, ("External authentication name: %s\n", conn->account.user));
     if (sasl_setprop (*saslconn, SASL_AUTH_EXTERNAL, conn->account.user) !=
         SASL_OK) {
       debug_print (1, ("Error setting external properties\n"));
       return -1;
     }
-#endif
   }
 
   return 0;
   }
 
   return 0;
@@ -393,20 +364,12 @@ void mutt_sasl_setup_conn (CONNECTION * conn, sasl_conn_t * saslconn)
 
   sasldata->saslconn = saslconn;
   /* get ssf so we know whether we have to (en|de)code read/write */
 
   sasldata->saslconn = saslconn;
   /* get ssf so we know whether we have to (en|de)code read/write */
-#ifdef USE_SASL2
   sasl_getprop (saslconn, SASL_SSF, (const void **) &sasldata->ssf);
   sasl_getprop (saslconn, SASL_SSF, (const void **) &sasldata->ssf);
-#else
-  sasl_getprop (saslconn, SASL_SSF, (void **) &sasldata->ssf);
-#endif
   debug_print (3, ("SASL protection strength: %u\n", *sasldata->ssf));
   /* Add SASL SSF to transport SSF */
   conn->ssf += *sasldata->ssf;
   debug_print (3, ("SASL protection strength: %u\n", *sasldata->ssf));
   /* Add SASL SSF to transport SSF */
   conn->ssf += *sasldata->ssf;
-#ifdef USE_SASL2
   sasl_getprop (saslconn, SASL_MAXOUTBUF,
                 (const void **) &sasldata->pbufsize);
   sasl_getprop (saslconn, SASL_MAXOUTBUF,
                 (const void **) &sasldata->pbufsize);
-#else
-  sasl_getprop (saslconn, SASL_MAXOUTBUF, (void **) &sasldata->pbufsize);
-#endif
   debug_print (3, ("SASL protection buffer size: %u\n", *sasldata->pbufsize));
 
   /* clear input buffer */
   debug_print (3, ("SASL protection buffer size: %u\n", *sasldata->pbufsize));
 
   /* clear input buffer */
@@ -533,9 +496,7 @@ static int mutt_sasl_conn_close (CONNECTION * conn)
 
   /* release sasl resources */
   sasl_dispose (&sasldata->saslconn);
 
   /* release sasl resources */
   sasl_dispose (&sasldata->saslconn);
-#ifndef USE_SASL2
   mem_free (&sasldata->buf);
   mem_free (&sasldata->buf);
-#endif
   mem_free (&sasldata);
 
   /* call underlying close */
   mem_free (&sasldata);
 
   /* call underlying close */
@@ -566,9 +527,7 @@ static int mutt_sasl_conn_read (CONNECTION * conn, char *buf, size_t len)
 
   conn->sockdata = sasldata->sockdata;
 
 
   conn->sockdata = sasldata->sockdata;
 
-#ifndef USE_SASL2
   mem_free (&sasldata->buf);
   mem_free (&sasldata->buf);
-#endif
   sasldata->bpos = 0;
   sasldata->blen = 0;
 
   sasldata->bpos = 0;
   sasldata->blen = 0;
 
@@ -613,11 +572,7 @@ static int mutt_sasl_conn_write (CONNECTION * conn, const char *buf,
   SASL_DATA *sasldata;
   int rc;
 
   SASL_DATA *sasldata;
   int rc;
 
-#ifdef USE_SASL2
   const char *pbuf;
   const char *pbuf;
-#else
-  char *pbuf;
-#endif
   unsigned int olen, plen;
 
   sasldata = (SASL_DATA *) conn->sockdata;
   unsigned int olen, plen;
 
   sasldata = (SASL_DATA *) conn->sockdata;
@@ -637,9 +592,7 @@ static int mutt_sasl_conn_write (CONNECTION * conn, const char *buf,
       }
 
       rc = (sasldata->msasl_write) (conn, pbuf, plen);
       }
 
       rc = (sasldata->msasl_write) (conn, pbuf, plen);
-#ifndef USE_SASL2
       mem_free (&pbuf);
       mem_free (&pbuf);
-#endif
       if (rc != plen)
         goto fail;
 
       if (rc != plen)
         goto fail;
 
index 9896cc5..b61eda3 100644 (file)
 #ifndef _MUTT_SASL_H_
 #define _MUTT_SASL_H_ 1
 
 #ifndef _MUTT_SASL_H_
 #define _MUTT_SASL_H_ 1
 
-#ifdef USE_SASL2
+#ifdef USE_SASL
 #include <sasl/sasl.h>
 #include <sasl/sasl.h>
-#else
-#include <sasl.h>
 #endif
 
 #include "mutt_socket.h"
 #endif
 
 #include "mutt_socket.h"
@@ -32,11 +30,7 @@ typedef struct {
   const unsigned int *pbufsize;
 
   /* read buffer */
   const unsigned int *pbufsize;
 
   /* read buffer */
-#ifdef USE_SASL2
   const char *buf;
   const char *buf;
-#else
-  char *buf;
-#endif
   unsigned int blen;
   unsigned int bpos;
 
   unsigned int blen;
   unsigned int bpos;
 
index a606ab9..81bebdd 100644 (file)
--- a/pattern.c
+++ b/pattern.c
 #include "lib/intl.h"
 #include "lib/str.h"
 
 #include "lib/intl.h"
 #include "lib/str.h"
 
+#ifdef USE_IMAP
+#include "mx.h"
+#include "imap/imap.h"
+#endif
+
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 #include <stdlib.h>
 #include <ctype.h>
@@ -38,6 +43,7 @@
 static int eat_regexp (pattern_t * pat, BUFFER *, BUFFER *);
 static int eat_date (pattern_t * pat, BUFFER *, BUFFER *);
 static int eat_range (pattern_t * pat, BUFFER *, BUFFER *);
 static int eat_regexp (pattern_t * pat, BUFFER *, BUFFER *);
 static int eat_date (pattern_t * pat, BUFFER *, BUFFER *);
 static int eat_range (pattern_t * pat, BUFFER *, BUFFER *);
+static int patmatch (const pattern_t* pat, const char* buf);
 
 struct pattern_flags {
   int tag;                      /* character used to represent this op */
 
 struct pattern_flags {
   int tag;                      /* character used to represent this op */
@@ -139,8 +145,7 @@ int mutt_which_case (const char *s)
 }
 
 static int
 }
 
 static int
-msg_search (CONTEXT * ctx, regex_t * rx, char *buf, size_t blen, int op,
-            int msgno)
+msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
 {
   char tempfile[_POSIX_PATH_MAX];
   MESSAGE *msg = NULL;
 {
   char tempfile[_POSIX_PATH_MAX];
   MESSAGE *msg = NULL;
@@ -150,6 +155,8 @@ msg_search (CONTEXT * ctx, regex_t * rx, char *buf, size_t blen, int op,
   long lng = 0;
   int match = 0;
   HEADER *h = ctx->hdrs[msgno];
   long lng = 0;
   int match = 0;
   HEADER *h = ctx->hdrs[msgno];
+  char* buf;
+  size_t blen;
 
   if ((msg = mx_open_message (ctx, msgno)) != NULL) {
     if (option (OPTTHOROUGHSRC)) {
 
   if ((msg = mx_open_message (ctx, msgno)) != NULL) {
     if (option (OPTTHOROUGHSRC)) {
@@ -163,10 +170,10 @@ msg_search (CONTEXT * ctx, regex_t * rx, char *buf, size_t blen, int op,
         return (0);
       }
 
         return (0);
       }
 
-      if (op != M_BODY)
+      if (pat->op != M_BODY)
         mutt_copy_header (msg->fp, h, s.fpout, CH_FROM | CH_DECODE, NULL);
 
         mutt_copy_header (msg->fp, h, s.fpout, CH_FROM | CH_DECODE, NULL);
 
-      if (op != M_HEADER) {
+      if (pat->op != M_HEADER) {
         mutt_parse_mime_message (ctx, h);
 
         if (WithCrypto && (h->security & ENCRYPT)
         mutt_parse_mime_message (ctx, h);
 
         if (WithCrypto && (h->security & ENCRYPT)
@@ -192,28 +199,36 @@ msg_search (CONTEXT * ctx, regex_t * rx, char *buf, size_t blen, int op,
     else {
       /* raw header / body */
       fp = msg->fp;
     else {
       /* raw header / body */
       fp = msg->fp;
-      if (op != M_BODY) {
+      if (pat->op != M_BODY) {
         fseek (fp, h->offset, 0);
         lng = h->content->offset - h->offset;
       }
         fseek (fp, h->offset, 0);
         lng = h->content->offset - h->offset;
       }
-      if (op != M_HEADER) {
-        if (op == M_BODY)
+      if (pat->op != M_HEADER) {
+        if (pat->op == M_BODY)
           fseek (fp, h->content->offset, 0);
         lng += h->content->length;
       }
     }
 
           fseek (fp, h->content->offset, 0);
         lng += h->content->length;
       }
     }
 
+    blen = STRING;
+    buf = mem_malloc (blen);
+
     /* search the file "fp" */
     while (lng > 0) {
     /* search the file "fp" */
     while (lng > 0) {
-      if (fgets (buf, blen - 1, fp) == NULL)
+      if (pat->op == M_HEADER) {
+        if (*(buf = mutt_read_rfc822_line (fp, buf, &blen)) == '\0')
+          break;
+      } if (fgets (buf, blen - 1, fp) == NULL)
         break;                  /* don't loop forever */
         break;                  /* don't loop forever */
-      if (regexec (rx, buf, 0, NULL, 0) == 0) {
+      if (patmatch (pat, buf) == 0) {
         match = 1;
         break;
       }
       lng -= str_len (buf);
     }
 
         match = 1;
         break;
       }
       lng -= str_len (buf);
     }
 
+    mem_free (&buf);
+
     mx_close_message (&msg);
 
     if (option (OPTTHOROUGHSRC)) {
     mx_close_message (&msg);
 
     if (option (OPTTHOROUGHSRC)) {
@@ -236,20 +251,37 @@ int eat_regexp (pattern_t * pat, BUFFER * s, BUFFER * err)
     snprintf (err->data, err->dsize, _("Error in expression: %s"), s->dptr);
     return (-1);
   }
     snprintf (err->data, err->dsize, _("Error in expression: %s"), s->dptr);
     return (-1);
   }
-  pat->rx = mem_malloc (sizeof (regex_t));
-  r =
-    REGCOMP (pat->rx, buf.data,
-             REG_NEWLINE | REG_NOSUB | mutt_which_case (buf.data));
-  mem_free (&buf.data);
-  if (r) {
-    regerror (r, pat->rx, err->data, err->dsize);
-    regfree (pat->rx);
-    mem_free (&pat->rx);
-    return (-1);
+
+#if 0
+ /* If there are no RE metacharacters, use simple search anyway */
+  if (!pat->stringmatch && !strpbrk (buf.data, "|[{.*+?^$"))
+    pat->stringmatch = 1;
+#endif
+
+  if (pat->stringmatch) {
+    pat->str = str_dup (buf.data);
+    mem_free (&buf.data);
+  } else {
+    pat->rx = mem_malloc (sizeof (regex_t));
+    r = REGCOMP (pat->rx, buf.data, REG_NEWLINE | REG_NOSUB | mutt_which_case (buf.data));
+    mem_free (&buf.data);
+    if (r) {
+      regerror (r, pat->rx, err->data, err->dsize);
+      regfree (pat->rx);
+      mem_free (&pat->rx);
+      return (-1);
+    }
   }
   return 0;
 }
 
   }
   return 0;
 }
 
+static int patmatch (const pattern_t* pat, const char* buf) {
+  if (pat->stringmatch)
+    return !strstr (buf, pat->str);
+  else
+    return regexec (pat->rx, buf, 0, NULL, 0);
+}
+
 int eat_range (pattern_t * pat, BUFFER * s, BUFFER * err)
 {
   char *tmp;
 int eat_range (pattern_t * pat, BUFFER * s, BUFFER * err)
 {
   char *tmp;
@@ -652,6 +684,7 @@ void mutt_pattern_free (pattern_t ** pat)
       regfree (tmp->rx);
       mem_free (&tmp->rx);
     }
       regfree (tmp->rx);
       mem_free (&tmp->rx);
     }
+    mem_free (tmp->str);
     if (tmp->child)
       mutt_pattern_free (&tmp->child);
     mem_free (&tmp);
     if (tmp->child)
       mutt_pattern_free (&tmp->child);
     mem_free (&tmp);
@@ -665,6 +698,7 @@ pattern_t *mutt_pattern_comp ( /* const */ char *s, int flags, BUFFER * err)
   pattern_t *last = NULL;
   int not = 0;
   int alladdr = 0;
   pattern_t *last = NULL;
   int not = 0;
   int alladdr = 0;
+  int stringmatch = 0;
   int or = 0;
   int implicit = 1;             /* used to detect logical AND operator */
   struct pattern_flags *entry;
   int or = 0;
   int implicit = 1;             /* used to detect logical AND operator */
   struct pattern_flags *entry;
@@ -710,7 +744,11 @@ pattern_t *mutt_pattern_comp ( /* const */ char *s, int flags, BUFFER * err)
       implicit = 0;
       not = 0;
       alladdr = 0;
       implicit = 0;
       not = 0;
       alladdr = 0;
+      stringmatch = 0;
       break;
       break;
+    case '=':
+      stringmatch = 1;
+      /* fallthrough */
     case '~':
       if (implicit && or) {
         /* A | B & C == (A | B) & C */
     case '~':
       if (implicit && or) {
         /* A | B & C == (A | B) & C */
@@ -725,8 +763,10 @@ pattern_t *mutt_pattern_comp ( /* const */ char *s, int flags, BUFFER * err)
       tmp = new_pattern ();
       tmp->not = not;
       tmp->alladdr = alladdr;
       tmp = new_pattern ();
       tmp->not = not;
       tmp->alladdr = alladdr;
+      tmp->stringmatch = stringmatch;
       not = 0;
       alladdr = 0;
       not = 0;
       alladdr = 0;
+      stringmatch = 0;
 
       if (last)
         last->next = tmp;
 
       if (last)
         last->next = tmp;
@@ -830,7 +870,7 @@ perform_or (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT * ctx,
   return 0;
 }
 
   return 0;
 }
 
-static int match_adrlist (regex_t * rx, int match_personal, int alladdr,
+static int match_adrlist (pattern_t* pat, int match_personal, int alladdr,
                           int n, ...)
 {
   va_list ap;
                           int n, ...)
 {
   va_list ap;
@@ -839,23 +879,23 @@ static int match_adrlist (regex_t * rx, int match_personal, int alladdr,
   va_start (ap, n);
   for (; n; n--) {
     for (a = va_arg (ap, ADDRESS *); a; a = a->next) {
   va_start (ap, n);
   for (; n; n--) {
     for (a = va_arg (ap, ADDRESS *); a; a = a->next) {
-      if (alladdr ^
-          ((a->mailbox && regexec (rx, a->mailbox, 0, NULL, 0) == 0) ||
+      if (pat->alladdr ^
+          ((a->mailbox && patmatch (pat, a->mailbox) == 0) ||
            (match_personal && a->personal &&
            (match_personal && a->personal &&
-            regexec (rx, a->personal, 0, NULL, 0) == 0))) {
+            patmatch (pat, a->personal) == 0))) {
         va_end (ap);
         va_end (ap);
-        return (!alladdr);      /* Found match, or non-match if alladdr */
+        return (!pat->alladdr);      /* Found match, or non-match if alladdr */
       }
     }
   }
   va_end (ap);
       }
     }
   }
   va_end (ap);
-  return alladdr;               /* No matches, or all matches if alladdr */
+  return pat->alladdr;               /* No matches, or all matches if alladdr */
 }
 
 }
 
-static int match_reference (regex_t * rx, LIST * refs)
+static int match_reference (pattern_t* pat, LIST * refs)
 {
   for (; refs; refs = refs->next)
 {
   for (; refs; refs = refs->next)
-    if (regexec (rx, refs->data, 0, NULL, 0) == 0)
+    if (patmatch (pat, refs->data) == 0)
       return 1;
   return 0;
 }
       return 1;
   return 0;
 }
@@ -918,8 +958,6 @@ int
 mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
                    CONTEXT * ctx, HEADER * h)
 {
 mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
                    CONTEXT * ctx, HEADER * h)
 {
-  char buf[STRING];
-
   switch (pat->op) {
   case M_AND:
     return (pat->not ^ (perform_and (pat->child, flags, ctx, h) > 0));
   switch (pat->op) {
   case M_AND:
     return (pat->not ^ (perform_and (pat->child, flags, ctx, h) > 0));
@@ -959,30 +997,32 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
   case M_BODY:
   case M_HEADER:
   case M_WHOLE_MSG:
   case M_BODY:
   case M_HEADER:
   case M_WHOLE_MSG:
-    return (pat->
-            not ^ msg_search (ctx, pat->rx, buf, sizeof (buf), pat->op,
-                              h->msgno));
+#ifdef USE_IMAP
+    /* IMAP search sets h->matched at search compile time */
+    if (Context->magic == M_IMAP && pat->stringmatch)
+      return (h->matched);
+#endif
+    return (pat->not ^ msg_search (ctx, pat, h->msgno));
   case M_SENDER:
   case M_SENDER:
-    return (pat->not ^ match_adrlist (pat->rx, flags & M_MATCH_FULL_ADDRESS,
+    return (pat->not ^ match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS,
                                       pat->alladdr, 1, h->env->sender));
   case M_FROM:
                                       pat->alladdr, 1, h->env->sender));
   case M_FROM:
-    return (pat->not ^ match_adrlist (pat->rx, flags & M_MATCH_FULL_ADDRESS,
+    return (pat->not ^ match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS,
                                       pat->alladdr, 1, h->env->from));
   case M_TO:
                                       pat->alladdr, 1, h->env->from));
   case M_TO:
-    return (pat->not ^ match_adrlist (pat->rx, flags & M_MATCH_FULL_ADDRESS,
+    return (pat->not ^ match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS,
                                       pat->alladdr, 1, h->env->to));
   case M_CC:
                                       pat->alladdr, 1, h->env->to));
   case M_CC:
-    return (pat->not ^ match_adrlist (pat->rx, flags & M_MATCH_FULL_ADDRESS,
+    return (pat->not ^ match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS,
                                       pat->alladdr, 1, h->env->cc));
   case M_SUBJECT:
     return (pat->
             not ^ (h->env && h->env->subject
                                       pat->alladdr, 1, h->env->cc));
   case M_SUBJECT:
     return (pat->
             not ^ (h->env && h->env->subject
-                   && regexec (pat->rx, h->env->subject, 0, NULL, 0) == 0));
+                   && patmatch (pat, h->env->subject) == 0));
   case M_ID:
     return (pat->
             not ^ (h->env && h->env->message_id
   case M_ID:
     return (pat->
             not ^ (h->env && h->env->message_id
-                   && regexec (pat->rx, h->env->message_id, 0, NULL,
-                               0) == 0));
+                   && patmatch (pat, h->env->message_id) == 0));
   case M_SCORE:
     return (pat->not ^ (h->score >= pat->min && (pat->max == M_MAXRANGE ||
                                                  h->score <= pat->max)));
   case M_SCORE:
     return (pat->not ^ (h->score >= pat->min && (pat->max == M_MAXRANGE ||
                                                  h->score <= pat->max)));
@@ -992,18 +1032,18 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
                    && (pat->max == M_MAXRANGE
                        || h->content->length <= pat->max)));
   case M_REFERENCE:
                    && (pat->max == M_MAXRANGE
                        || h->content->length <= pat->max)));
   case M_REFERENCE:
-    return (pat->not ^ match_reference (pat->rx, h->env->references));
+    return (pat->not ^ match_reference (pat, h->env->references));
   case M_ADDRESS:
     return (pat->
             not ^ (h->env
   case M_ADDRESS:
     return (pat->
             not ^ (h->env
-                   && match_adrlist (pat->rx, flags & M_MATCH_FULL_ADDRESS,
+                   && match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS,
                                      pat->alladdr, 4, h->env->from,
                                      h->env->sender, h->env->to,
                                      h->env->cc)));
   case M_RECIPIENT:
     return (pat->
             not ^ (h->env
                                      pat->alladdr, 4, h->env->from,
                                      h->env->sender, h->env->to,
                                      h->env->cc)));
   case M_RECIPIENT:
     return (pat->
             not ^ (h->env
-                   && match_adrlist (pat->rx, flags & M_MATCH_FULL_ADDRESS,
+                   && match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS,
                                      pat->alladdr, 2, h->env->to,
                                      h->env->cc)));
   case M_LIST:
                                      pat->alladdr, 2, h->env->to,
                                      h->env->cc)));
   case M_LIST:
@@ -1045,12 +1085,11 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
   case M_XLABEL:
     return (pat->
             not ^ (h->env->x_label
   case M_XLABEL:
     return (pat->
             not ^ (h->env->x_label
-                   && regexec (pat->rx, h->env->x_label, 0, NULL, 0) == 0));
+                   && patmatch (pat, h->env->x_label) == 0));
   case M_HORMEL:
     return (pat->
             not ^ (h->env->spam && h->env->spam->data
   case M_HORMEL:
     return (pat->
             not ^ (h->env->spam && h->env->spam->data
-                   && regexec (pat->rx, h->env->spam->data, 0, NULL,
-                               0) == 0));
+                   && patmatch (pat, h->env->spam->data) == 0));
   case M_DUPLICATED:
     return (pat->not ^ (h->thread && h->thread->duplicate_thread));
   case M_UNREFERENCED:
   case M_DUPLICATED:
     return (pat->not ^ (h->thread && h->thread->duplicate_thread));
   case M_UNREFERENCED:
@@ -1079,8 +1118,7 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
   case M_NEWSGROUPS:
     return (pat->
             not ^ (h->env->newsgroups
   case M_NEWSGROUPS:
     return (pat->
             not ^ (h->env->newsgroups
-                   && regexec (pat->rx, h->env->newsgroups, 0, NULL,
-                               0) == 0));
+                   && patmatch (pat, h->env->newsgroups) == 0));
 #endif
   }
   mutt_error (_("error: unknown op %d (report this error)."), pat->op);
 #endif
   }
   mutt_error (_("error: unknown op %d (report this error)."), pat->op);
@@ -1110,7 +1148,7 @@ void mutt_check_simple (char *s, size_t len, const char *simple)
    * equivalences?
    */
 
    * equivalences?
    */
 
-  if (!strchr (s, '~')) {       /* yup, so spoof a real request */
+  if (!strchr (s, '~') && !strchr (s, '=')) {       /* yup, so spoof a real request */
     /* convert old tokens into the new format */
     if (ascii_strcasecmp ("all", s) == 0 || !str_cmp ("^", s) || !str_cmp (".", s))     /* ~A is more efficient */
       strfcpy (s, "~A", len);
     /* convert old tokens into the new format */
     if (ascii_strcasecmp ("all", s) == 0 || !str_cmp ("^", s) || !str_cmp (".", s))     /* ~A is more efficient */
       strfcpy (s, "~A", len);
@@ -1168,6 +1206,11 @@ int mutt_pattern_func (int op, char *prompt)
     return (-1);
   }
 
     return (-1);
   }
 
+#ifdef USE_IMAP
+  if (Context->magic == M_IMAP && imap_search (Context, pat) < 0)
+    return -1;
+#endif
+
   mutt_message _("Executing command on matching messages...");
 
 #define THIS_BODY Context->hdrs[i]->content
   mutt_message _("Executing command on matching messages...");
 
 #define THIS_BODY Context->hdrs[i]->content
@@ -1294,6 +1337,10 @@ int mutt_search_command (int cur, int op)
   if (option (OPTSEARCHINVALID)) {
     for (i = 0; i < Context->msgcount; i++)
       Context->hdrs[i]->searched = 0;
   if (option (OPTSEARCHINVALID)) {
     for (i = 0; i < Context->msgcount; i++)
       Context->hdrs[i]->searched = 0;
+#ifdef USE_IMAP
+    if (Context->magic == M_IMAP && imap_search (Context, SearchPattern) < 0)
+      return -1;
+#endif
     unset_option (OPTSEARCHINVALID);
   }
 
     unset_option (OPTSEARCHINVALID);
   }
 
index 919a3ab..75fe93c 100644 (file)
 #include <unistd.h>
 
 #ifdef USE_SASL
 #include <unistd.h>
 
 #ifdef USE_SASL
-#ifdef USE_SASL2
 #include <sasl/sasl.h>
 #include <sasl/saslutil.h>
 #include <sasl/sasl.h>
 #include <sasl/saslutil.h>
-#else
-#include <sasl.h>
-#include <saslutil.h>
-#endif
-
 #include "mutt_sasl.h"
 #endif
 
 #include "mutt_sasl.h"
 #endif
 
@@ -47,10 +41,8 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
   char inbuf[LONG_STRING];
   const char *mech;
 
   char inbuf[LONG_STRING];
   const char *mech;
 
-#ifdef USE_SASL2
+#ifdef USE_SASL
   const char *pc = NULL;
   const char *pc = NULL;
-#else
-  char *pc = NULL;
 #endif
   unsigned int len, olen;
   unsigned char client_start;
 #endif
   unsigned int len, olen;
   unsigned char client_start;
@@ -64,12 +56,9 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
     method = pop_data->auth_list;
 
   FOREVER {
     method = pop_data->auth_list;
 
   FOREVER {
-#ifdef USE_SASL2
+#ifdef USE_SASL
     rc =
       sasl_client_start (saslconn, method, &interaction, &pc, &olen, &mech);
     rc =
       sasl_client_start (saslconn, method, &interaction, &pc, &olen, &mech);
-#else
-    rc = sasl_client_start (saslconn, method, NULL,
-                            &interaction, &pc, &olen, &mech);
 #endif
     if (rc != SASL_INTERACT)
       break;
 #endif
     if (rc != SASL_INTERACT)
       break;
@@ -103,13 +92,10 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
     if (rc != SASL_CONTINUE)
       break;
 
     if (rc != SASL_CONTINUE)
       break;
 
-#ifdef USE_SASL2
+#ifdef USE_SASL
     if (!str_ncmp (inbuf, "+ ", 2)
         && sasl_decode64 (inbuf, strlen (inbuf), buf, LONG_STRING - 1,
                           &len) != SASL_OK)
     if (!str_ncmp (inbuf, "+ ", 2)
         && sasl_decode64 (inbuf, strlen (inbuf), buf, LONG_STRING - 1,
                           &len) != SASL_OK)
-#else
-    if (!str_ncmp (inbuf, "+ ", 2)
-        && sasl_decode64 (inbuf, strlen (inbuf), buf, &len) != SASL_OK)
 #endif
     {
       debug_print (1, ("error base64-decoding server response.\n"));
 #endif
     {
       debug_print (1, ("error base64-decoding server response.\n"));
@@ -138,7 +124,7 @@ static pop_auth_res_t pop_auth_sasl (POP_DATA * pop_data, const char *method)
 
       /* sasl_client_st(art|ep) allocate pc with malloc, expect me to 
        * free it */
 
       /* sasl_client_st(art|ep) allocate pc with malloc, expect me to 
        * free it */
-#ifndef USE_SASL2
+#ifndef USE_SASL
       mem_free (&pc);
 #endif
     }
       mem_free (&pc);
 #endif
     }