Coverity fixes
[claws.git] / src / matcher.c
index c95655cf49889b1e5a05b94d0ff8c7bbb3d5f4bc..4382c5996aa534ebba0f523f39b38da8edeffc0e 100644 (file)
@@ -313,7 +313,9 @@ MatcherProp *matcherprop_new(gint criteria, const gchar *header,
        prop->expr = expr != NULL ? g_strdup(expr) : NULL;
 
        prop->matchtype = matchtype;
+#ifndef G_OS_WIN32
        prop->preg = NULL;
+#endif
        prop->value = value;
        prop->error = 0;
 
@@ -330,10 +332,12 @@ void matcherprop_free(MatcherProp *prop)
 {
        g_free(prop->expr);
        g_free(prop->header);
+#ifndef G_OS_WIN32
        if (prop->preg != NULL) {
                regfree(prop->preg);
                g_free(prop->preg);
        }
+#endif
        g_free(prop);
 }
 
@@ -353,7 +357,9 @@ MatcherProp *matcherprop_copy(const MatcherProp *src)
        prop->expr = src->expr ? g_strdup(src->expr) : NULL;
        prop->matchtype = src->matchtype;
        
+#ifndef G_OS_WIN32
        prop->preg = NULL; /* will be re-evaluated */
+#endif
        prop->value = src->value;
        prop->error = src->error;       
        return prop;            
@@ -1188,10 +1194,12 @@ static gchar *build_complete_regexp(gchar **strings)
  *
  *\param       lines String with "\n"-separated expressions
  *\param       bool_and Operator
+ *\param       case_sensitive If the matching is case sensitive or not
  *
  *\return      MatcherList * New matcher list
  */
-MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
+MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and, 
+                                       gboolean case_sensitive)
 {
        MatcherProp *m = NULL;
        GSList *matchers = NULL;
@@ -1202,8 +1210,9 @@ MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
        expr = build_complete_regexp(strings);
        debug_print("building matcherprop for expr '%s'\n", expr?expr:"NULL");
        
-       m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_REGEXP, 
-                           expr, 0);
+       m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL,
+                       case_sensitive? MATCHTYPE_REGEXP: MATCHTYPE_REGEXPCASE,
+                       expr, 0);
        if (m == NULL) {
                /* print error message */
                debug_print("failed to allocate memory for matcherprop\n");
@@ -1215,8 +1224,9 @@ MatcherList *matcherlist_new_from_lines(gchar *lines, gboolean bool_and)
 #else
        int i = 0;
        while (strings && strings[i] && *strings[i]) {
-               m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL, MATCHTYPE_MATCHCASE, 
-                           strings[i], 0);
+               m = matcherprop_new(MATCHCRITERIA_SUBJECT, NULL,
+                       case_sensitive? MATCHTYPE_MATCH: MATCHTYPE_MATCHCASE,
+                       strings[i], 0);
                if (m == NULL) {
                        /* print error message */
                        debug_print("failed to allocate memory for matcherprop\n");
@@ -1521,7 +1531,7 @@ static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo
        gchar buf[BUFFSIZE];
        GSList *l;
 
-       if (partinfo->type == MIMETYPE_TEXT)
+       if (!partinfo || partinfo->type == MIMETYPE_TEXT)
                return FALSE;
        else
                outfp = procmime_get_binary_content(partinfo);
@@ -1541,9 +1551,8 @@ static gboolean matcherlist_match_binary_content(MatcherList *matchers, MimeInfo
                        /* Don't scan non-text parts when looking in body, only
                         * when looking in whole message
                         */
-                       if (partinfo && partinfo->type != MIMETYPE_TEXT &&
-                       (matcher->criteria == MATCHCRITERIA_NOT_BODY_PART ||
-                       matcher->criteria == MATCHCRITERIA_BODY_PART))
+                       if (matcher->criteria == MATCHCRITERIA_NOT_BODY_PART ||
+                           matcher->criteria == MATCHCRITERIA_BODY_PART)
                                continue;
 
                        /* if the criteria is ~body_part or ~message, ZERO lines