[evolution-data-server] Bug #700895 - Decode header's value before comparing with RegEx
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug #700895 - Decode header's value before comparing with RegEx
- Date: Fri, 9 Aug 2013 16:50:15 +0000 (UTC)
commit 4dd87a62db59010fd2f7f73b5406a66ae7d02256
Author: Milan Crha <mcrha redhat com>
Date: Fri Aug 9 18:49:49 2013 +0200
Bug #700895 - Decode header's value before comparing with RegEx
camel/camel-folder-search.c | 69 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 66 insertions(+), 3 deletions(-)
---
diff --git a/camel/camel-folder-search.c b/camel/camel-folder-search.c
index 0373c9b..da446dd 100644
--- a/camel/camel-folder-search.c
+++ b/camel/camel-folder-search.c
@@ -608,8 +608,43 @@ match_words_messages (CamelFolderSearch *search,
return matches;
}
+static const gchar *
+get_default_charset (CamelMimeMessage *msg)
+{
+ CamelContentType *ct;
+ const gchar *charset;
+
+ g_return_val_if_fail (msg != NULL, NULL);
+
+ ct = camel_mime_part_get_content_type (CAMEL_MIME_PART (msg));
+ charset = camel_content_type_param (ct, "charset");
+ if (!charset)
+ charset = "utf-8";
+
+ charset = camel_iconv_charset_name (charset);
+
+ return charset;
+}
+
+static gchar *
+get_header_decoded (const gchar *header_value,
+ const gchar *default_charset)
+{
+ gchar *unfold, *decoded;
+
+ if (!header_value || !*header_value)
+ return NULL;
+
+ unfold = camel_header_unfold (header_value);
+ decoded = camel_header_decode_string (unfold, default_charset);
+ g_free (unfold);
+
+ return decoded;
+}
+
static gchar *
-get_full_header (CamelMimeMessage *message)
+get_full_header (CamelMimeMessage *message,
+ const gchar *default_charset)
{
CamelMimePart *mp = CAMEL_MIME_PART (message);
GString *str = g_string_new ("");
@@ -622,7 +657,20 @@ get_full_header (CamelMimeMessage *message)
g_string_append (str, ":");
else
g_string_append (str, ": ");
- g_string_append (str, h->value);
+ if (g_ascii_strcasecmp (h->name, "From") == 0 ||
+ g_ascii_strcasecmp (h->name, "To") == 0 ||
+ g_ascii_strcasecmp (h->name, "CC") == 0 ||
+ g_ascii_strcasecmp (h->name, "BCC") == 0 ||
+ g_ascii_strcasecmp (h->name, "Subject") == 0) {
+ gchar *decoded = get_header_decoded (h->value, default_charset);
+ if (decoded)
+ g_string_append (str, decoded);
+ else
+ g_string_append (str, h->value);
+ g_free (decoded);
+ } else {
+ g_string_append (str, h->value);
+ }
g_string_append_c (str, '\n');
}
}
@@ -1265,8 +1313,23 @@ folder_search_header_regex (CamelSExp *sexp,
CAMEL_SEARCH_MATCH_ICASE,
argc - 1, argv + 1,
search->priv->error) == 0) {
+ gchar *decoded = NULL;
+ const gchar *hader_name = argv[0]->value.string;
+
+ if (g_ascii_strcasecmp (hader_name, "From") == 0 ||
+ g_ascii_strcasecmp (hader_name, "To") == 0 ||
+ g_ascii_strcasecmp (hader_name, "CC") == 0 ||
+ g_ascii_strcasecmp (hader_name, "BCC") == 0 ||
+ g_ascii_strcasecmp (hader_name, "Subject") == 0) {
+ decoded = get_header_decoded (contents, get_default_charset (msg));
+ if (decoded)
+ contents = decoded;
+ }
+
r->value.boolean = regexec (&pattern, contents, 0, NULL, 0) == 0;
regfree (&pattern);
+
+ g_free (decoded);
} else
r->value.boolean = FALSE;
@@ -1304,7 +1367,7 @@ folder_search_header_full_regex (CamelSExp *sexp,
search->priv->error) == 0) {
gchar *contents;
- contents = get_full_header (msg);
+ contents = get_full_header (msg, get_default_charset (msg));
r->value.boolean = regexec (&pattern, contents, 0, NULL, 0) == 0;
g_free (contents);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]