Don't bother parsing headers when we want to skip them
authorColin Leroy <colin@colino.net>
Sat, 6 Oct 2018 10:46:48 +0000 (12:46 +0200)
committerColin Leroy <colin@colino.net>
Sat, 6 Oct 2018 10:46:48 +0000 (12:46 +0200)
Speeds up body-only search

src/matcher.c
src/procheader.c
src/procheader.h

index 4a0392d678020101ffe62ec9b76fc291b9180752..c58c559646f846750044b180a21850b85c2fc270 100644 (file)
@@ -1329,19 +1329,6 @@ void matcherlist_free(MatcherList *cond)
        g_free(cond);
 }
 
        g_free(cond);
 }
 
-/*!
- *\brief       Skip all headers in a message file
- *
- *\param       fp Message file
- */
-static void matcherlist_skip_headers(FILE *fp)
-{
-       gchar *buf = NULL;
-
-       while (procheader_get_one_field(&buf, fp, NULL) != -1)
-               g_free(buf);
-}
-
 /*!
  *\brief       Check if a header matches a matcher condition
  *
 /*!
  *\brief       Check if a header matches a matcher condition
  *
@@ -1848,7 +1835,7 @@ static gboolean matcherlist_match_file(MatcherList *matchers, MsgInfo *info,
                if (matcherlist_match_headers(matchers, fp))
                        read_body = FALSE;
        } else {
                if (matcherlist_match_headers(matchers, fp))
                        read_body = FALSE;
        } else {
-               matcherlist_skip_headers(fp);
+               procheader_skip_headers(fp);
        }
 
        /* read the body */
        }
 
        /* read the body */
index 174e283dbddfa23a053021912646df1bdbe646fe..6a98f129cf1632ccc46412a6e614b46aa621aefc 100644 (file)
@@ -83,6 +83,24 @@ static gint string_get_one_field(gchar **buf, char **str,
                                     TRUE);
 }
 
                                     TRUE);
 }
 
+gboolean procheader_skip_headers(FILE *fp)
+{
+       gchar *buf = g_malloc(BUFFSIZE);
+       do {
+               if (fgets_crlf(buf, BUFFSIZE - 1, fp) == NULL) {
+                       g_free(buf);
+                       return FALSE;
+               }
+               if (buf[0] == '\r' || buf[0] == '\n') {
+                       break;
+               }
+       } while (TRUE);
+       g_free(buf);
+
+       return TRUE;
+}
+
+
 static char *string_getline(char *buf, size_t len, char **str)
 {
        gboolean is_cr = FALSE;
 static char *string_getline(char *buf, size_t len, char **str)
 {
        gboolean is_cr = FALSE;
index 0588f305e2348ae82c26b91da310e5a1e25ce0bf..50e6c556ba3e54974ab8cf46b7839f52452a1b3c 100644 (file)
@@ -51,6 +51,8 @@ GPtrArray *procheader_get_header_array_asis   (FILE           *fp);
 void procheader_header_array_destroy           (GPtrArray      *harray);
 void procheader_header_free                    (Header         *header);
 
 void procheader_header_array_destroy           (GPtrArray      *harray);
 void procheader_header_free                    (Header         *header);
 
+gboolean procheader_skip_headers(FILE *fp);
+
 void procheader_get_header_fields      (FILE           *fp,
                                         HeaderEntry     hentry[]);
 MsgInfo *procheader_parse_file         (const gchar    *file,
 void procheader_get_header_fields      (FILE           *fp,
                                         HeaderEntry     hentry[]);
 MsgInfo *procheader_parse_file         (const gchar    *file,