#include "matcher_parser.h"
#include "prefs_gtk.h"
#include "addr_compl.h"
+#include "codeconv.h"
+#include "quoted-printable.h"
#include <ctype.h>
/*!
*/
void matcherprop_free(MatcherProp *prop)
{
- if (prop->expr)
- g_free(prop->expr);
- if (prop->header)
- g_free(prop->header);
+ g_free(prop->expr);
+ g_free(prop->header);
if (prop->preg != NULL) {
regfree(prop->preg);
g_free(prop->preg);
}
}
+/* FIXME body search is a hack. */
+static gboolean matcherprop_string_decode_match(MatcherProp *prop, const gchar *str)
+{
+ gchar *utf = NULL;
+ gchar tmp[BUFFSIZE];
+ gboolean res = FALSE;
+
+ if (str == NULL)
+ return FALSE;
+
+ /* we try to decode QP first, because it's faster than base64 */
+ qp_decode_const(tmp, BUFFSIZE-1, str);
+ if (!g_utf8_validate(tmp, -1, NULL)) {
+ utf = conv_codeset_strdup
+ (tmp, conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL);
+ res = matcherprop_string_match(prop, utf);
+ g_free(utf);
+ } else {
+ res = matcherprop_string_match(prop, tmp);
+ }
+
+ if (res == FALSE && (strchr(prop->expr, '=') || strchr(prop->expr, '_')) ) {
+ /* if searching for something with an equal char, maybe
+ * we should try to match the non-decoded string.
+ * In case it was not qp-encoded. */
+ if (!g_utf8_validate(str, -1, NULL)) {
+ utf = conv_codeset_strdup
+ (str, conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL);
+ res = matcherprop_string_match(prop, utf);
+ } else {
+ res = matcherprop_string_match(prop, str);
+ }
+ }
+
+ /* FIXME base64 decoding is too slow, especially since text can
+ * easily be handled as base64. Don't even try now. */
+
+ return res;
+}
+
/*!
*\brief Execute a command defined in the matcher structure
*
}
break;
case MATCHCRITERIA_HEADERS_PART:
- case MATCHCRITERIA_MESSAGE:
return matcherprop_string_match(matcher, buf);
+ case MATCHCRITERIA_MESSAGE:
+ return matcherprop_string_decode_match(matcher, buf);
case MATCHCRITERIA_NOT_MESSAGE:
+ return !matcherprop_string_decode_match(matcher, buf);
case MATCHCRITERIA_NOT_HEADERS_PART:
return !matcherprop_string_match(matcher, buf);
}
switch (matcher->criteria) {
case MATCHCRITERIA_BODY_PART:
case MATCHCRITERIA_MESSAGE:
- return matcherprop_string_match(matcher, line);
+ return matcherprop_string_decode_match(matcher, line);
case MATCHCRITERIA_NOT_BODY_PART:
case MATCHCRITERIA_NOT_MESSAGE:
- return !matcherprop_string_match(matcher, line);
+ return !matcherprop_string_decode_match(matcher, line);
}
return FALSE;
}
GSList *l;
gboolean result;
+ if (!matchers)
+ return FALSE;
+
if (matchers->bool_and)
result = TRUE;
else
if (NULL == (filtering_str = filteringprop_to_string(prop)))
continue;
-
+
+ if (prop->enabled) {
+ if (fputs("enabled ", fp) == EOF) {
+ FILE_OP_ERROR("filtering config", "fputs || fputc");
+ return;
+ }
+ } else {
+ if (fputs("disabled ", fp) == EOF) {
+ FILE_OP_ERROR("filtering config", "fputs || fputc");
+ return;
+ }
+ }
+
if (fputs("rulename \"", fp) == EOF) {
FILE_OP_ERROR("filtering config", "fputs || fputc");
g_free(filtering_str);