Fix compilation warnings in pattern.c
[apps/madmutt.git] / pattern.c
index b1dba84..35cdbd9 100644 (file)
--- a/pattern.c
+++ b/pattern.c
 #include <lib-lib/buffer.h>
 #include <lib-lib/mapping.h>
 
+#include <lib-mime/mime.h>
+
 #include "mutt.h"
 #include "handler.h"
 #include "enter.h"
 #include "mx.h"
 #include "keymap.h"
 #include "copy.h"
-#include "mime.h"
-
 
-#ifdef USE_IMAP
-#include "mx.h"
-#include "imap/imap.h"
-#endif
+#include <imap/imap.h>
 
 #include <string.h>
 #include <stdlib.h>
@@ -40,7 +37,7 @@
 #include <unistd.h>
 #include <stdarg.h>
 
-#include "mutt_crypt.h"
+#include <lib-crypt/crypt.h>
 
 static int eat_regexp (pattern_t * pat, BUFFER *, BUFFER *);
 static int eat_date (pattern_t * pat, BUFFER *, BUFFER *);
@@ -159,7 +156,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
   int match = 0;
   HEADER *h = ctx->hdrs[msgno];
   char* buf;
-  size_t blen;
+  ssize_t blen;
 
   if ((msg = mx_open_message (ctx, msgno)) != NULL) {
     if (option (OPTTHOROUGHSRC)) {
@@ -179,8 +176,8 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
       if (pat->op != M_HEADER) {
         mutt_parse_mime_message (ctx, h);
 
-        if (WithCrypto && (h->security & ENCRYPT)
-            && !crypt_valid_passphrase (h->security)) {
+        if ((h->security & ENCRYPT) && !crypt_valid_passphrase (h->security))
+        {
           mx_close_message (&msg);
           if (fp) {
             fclose (fp);
@@ -218,7 +215,7 @@ msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
     /* search the file "fp" */
     while (lng > 0) {
       if (pat->op == M_HEADER) {
-        if (*(buf = mutt_read_rfc822_line (fp, buf, &blen)) == '\0')
+        if (!mutt_read_rfc822_line(fp, &buf, &blen))
           break;
       } else if (fgets (buf, blen - 1, fp) == NULL)
         break;                  /* don't loop forever */
@@ -290,7 +287,7 @@ static int patmatch (const pattern_t* pat, const char* buf) {
     return regexec (pat->rx, buf, 0, NULL, 0);
 }
 
-int eat_range (pattern_t * pat, BUFFER * s, BUFFER * err)
+int eat_range (pattern_t * pat, BUFFER * s, BUFFER * err __attribute__ ((unused)))
 {
   char *tmp;
   int do_exclusive = 0;
@@ -815,7 +812,7 @@ pattern_t *mutt_pattern_comp ( /* const */ char *s, int flags, BUFFER * err)
         return NULL;
       }
       /* compile the sub-expression */
-      buf = str_substrdup (ps.dptr + 1, p);
+      buf = p_dupstr(ps.dptr + 1, p - ps.dptr - 1);
       if ((tmp = mutt_pattern_comp (buf, flags, err)) == NULL) {
         p_delete(&buf);
         mutt_pattern_free (&curlist);
@@ -872,15 +869,15 @@ perform_or (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT * ctx,
   return 0;
 }
 
-static int match_adrlist (pattern_t* pat, int match_personal, int alladdr,
+static int match_adrlist (pattern_t* pat, int match_personal, int alladdr __attribute__ ((unused)),
                           int n, ...)
 {
   va_list ap;
-  ADDRESS *a;
+  address_t *a;
 
   va_start (ap, n);
   for (; n; n--) {
-    for (a = va_arg (ap, ADDRESS *); a; a = a->next) {
+    for (a = va_arg (ap, address_t *); a; a = a->next) {
       if (pat->alladdr ^
           ((a->mailbox && patmatch (pat, a->mailbox) == 0) ||
            (match_personal && a->personal &&
@@ -902,7 +899,7 @@ static int match_reference (pattern_t* pat, LIST * refs)
   return 0;
 }
 
-int mutt_is_list_recipient (int alladdr, ADDRESS * a1, ADDRESS * a2)
+int mutt_is_list_recipient (int alladdr, address_t * a1, address_t * a2)
 {
   for (; a1; a1 = a1->next)
     if (alladdr ^ mutt_is_subscribed_list (a1))
@@ -913,7 +910,7 @@ int mutt_is_list_recipient (int alladdr, ADDRESS * a1, ADDRESS * a2)
   return alladdr;
 }
 
-int mutt_is_list_cc (int alladdr, ADDRESS * a1, ADDRESS * a2)
+int mutt_is_list_cc (int alladdr, address_t * a1, address_t * a2)
 {
   for (; a1; a1 = a1->next)
     if (alladdr ^ mutt_is_mail_list (a1))
@@ -924,7 +921,7 @@ int mutt_is_list_cc (int alladdr, ADDRESS * a1, ADDRESS * a2)
   return alladdr;
 }
 
-static int match_user (int alladdr, ADDRESS * a1, ADDRESS * a2)
+static int match_user (int alladdr, address_t * a1, address_t * a2)
 {
   for (; a1; a1 = a1->next)
     if (alladdr ^ mutt_addr_is_user (a1))
@@ -999,11 +996,9 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
   case M_BODY:
   case M_HEADER:
   case M_WHOLE_MSG:
-#ifdef USE_IMAP
     /* IMAP search sets h->matched at search compile time */
     if (ctx->magic == M_IMAP && pat->stringmatch)
       return (h->matched);
-#endif
     return (pat->not ^ msg_search (ctx, pat, h->msgno));
   case M_SENDER:
     return (pat->not ^ match_adrlist (pat, flags & M_MATCH_FULL_ADDRESS,
@@ -1068,20 +1063,12 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
   case M_COLLAPSED:
     return (pat->not ^ (h->collapsed && h->num_hidden > 1));
   case M_CRYPT_SIGN:
-    if (!WithCrypto)
-      break;
     return (pat->not ^ ((h->security & SIGN) ? 1 : 0));
   case M_CRYPT_VERIFIED:
-    if (!WithCrypto)
-      break;
     return (pat->not ^ ((h->security & GOODSIGN) ? 1 : 0));
   case M_CRYPT_ENCRYPT:
-    if (!WithCrypto)
-      break;
     return (pat->not ^ ((h->security & ENCRYPT) ? 1 : 0));
   case M_PGP_KEY:
-    if (!(WithCrypto & APPLICATION_PGP))
-      break;
     return (pat->not ^ ((h->security & APPLICATION_PGP)
                         && (h->security & PGPKEY)));
   case M_XLABEL:
@@ -1144,9 +1131,9 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags,
   return (-1);
 }
 
-static void quote_simple (char *tmp, size_t len, const char *p)
+static void quote_simple (char *tmp, ssize_t len, const char *p)
 {
-  int i = 0;
+  ssize_t i = 0;
 
   tmp[i++] = '"';
   while (*p && i < len - 3) {
@@ -1219,10 +1206,8 @@ int mutt_pattern_func (int op, char *prompt)
     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...");
 
@@ -1350,10 +1335,8 @@ int mutt_search_command (int cur, int op)
   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);
   }