[balsa] Compare string conditions correctly
- From: Peter Bloomfield <PeterB src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [balsa] Compare string conditions correctly
- Date: Mon, 25 Jan 2010 19:08:34 +0000 (UTC)
commit 1f76169f201092d832bb247cb6fb1ec3e1cfb7d4
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Mon Jan 25 14:06:52 2010 -0500
Compare string conditions correctly
* libbalsa/filter-funcs.c (lbcond_compare_string_conditions),
(libbalsa_condition_compare): compare string conditions
correctly.
* libbalsa/mailbox_local.c (message_match_real): do not pass
NULL list to internet_address_list_to_string().
ChangeLog | 8 ++++++++
libbalsa/filter-funcs.c | 17 +++++++++++++++--
libbalsa/mailbox_local.c | 45 +++++++++++++++++++++++++--------------------
3 files changed, 48 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b548853..77c7670 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-01-25 Peter Bloomfield
+
+ * libbalsa/filter-funcs.c (lbcond_compare_string_conditions),
+ (libbalsa_condition_compare): compare string conditions
+ correctly.
+ * libbalsa/mailbox_local.c (message_match_real): do not pass
+ NULL list to internet_address_list_to_string().
+
2010-01-24 Pawel Salek
* configure.in, NEWS: release 2.4.5
diff --git a/libbalsa/filter-funcs.c b/libbalsa/filter-funcs.c
index df80acf..4fbf7dd 100644
--- a/libbalsa/filter-funcs.c
+++ b/libbalsa/filter-funcs.c
@@ -487,6 +487,20 @@ compare_regexs(GSList * c1,GSList * c2)
NULL conditions are OK, and compare equal only if both are NULL.
*/
+static gboolean
+lbcond_compare_string_conditions(LibBalsaCondition * c1,
+ LibBalsaCondition * c2)
+{
+ if (c1->match.string.fields != c2->match.string.fields
+ || (CONDITION_CHKMATCH(c1, CONDITION_MATCH_US_HEAD)
+ && g_ascii_strcasecmp(c1->match.string.user_header,
+ c2->match.string.user_header)))
+ return FALSE;
+
+ return (g_ascii_strcasecmp(c1->match.string.string,
+ c2->match.string.string) == 0);
+}
+
gboolean
libbalsa_condition_compare(LibBalsaCondition *c1,LibBalsaCondition *c2)
{
@@ -501,8 +515,7 @@ libbalsa_condition_compare(LibBalsaCondition *c1,LibBalsaCondition *c2)
switch (c1->type) {
case CONDITION_STRING:
- res = (g_ascii_strcasecmp(c1->match.string.string,
- c2->match.string.string) == 0);
+ res = lbcond_compare_string_conditions(c1, c2);
break;
case CONDITION_REGEX:
#if 0
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 316e294..d230529 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -807,7 +807,6 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
LibBalsaMessage *message = NULL;
gboolean match = FALSE;
gboolean is_refed = FALSE;
- gchar *str;
LibBalsaMailboxIndexEntry *entry =
g_ptr_array_index(mailbox->mindex, msgno-1);
LibBalsaMailboxLocalInfo *info =
@@ -833,8 +832,9 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
switch (cond->type) {
case CONDITION_STRING:
- if (CONDITION_CHKMATCH
- (cond, (CONDITION_MATCH_CC | CONDITION_MATCH_BODY))) {
+ if (CONDITION_CHKMATCH(cond, (CONDITION_MATCH_TO |
+ CONDITION_MATCH_CC |
+ CONDITION_MATCH_BODY))) {
if (!message)
message = libbalsa_mailbox_get_message(mailbox, msgno);
if (!message)
@@ -844,23 +844,24 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
libbalsa_information(LIBBALSA_INFORMATION_ERROR,
_("Unable to load message body to "
"match filter"));
- if (message)
- g_object_unref(message);
+ g_object_unref(message);
return FALSE; /* We don't want to match if an error occurred */
}
}
/* do the work */
if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_TO)) {
- if (!message)
- message = libbalsa_mailbox_get_message(mailbox, msgno);
- if (!message)
- return FALSE;
- str = internet_address_list_to_string(message->headers->to_list,
- FALSE);
- match = libbalsa_utf8_strstr(str,cond->match.string.string);
- g_free(str);
- if(match) break;
+ g_assert(is_refed);
+ if (message->headers->to_list) {
+ gchar *str =
+ internet_address_list_to_string(message->headers->
+ to_list, FALSE);
+ match =
+ libbalsa_utf8_strstr(str, cond->match.string.string);
+ g_free(str);
+ if (match)
+ break;
+ }
}
if (CONDITION_CHKMATCH(cond, CONDITION_MATCH_FROM)) {
if (libbalsa_utf8_strstr(info->sender,
@@ -878,12 +879,16 @@ message_match_real(LibBalsaMailbox *mailbox, guint msgno,
}
if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_CC)) {
g_assert(is_refed);
- str =
- internet_address_list_to_string(message->headers->cc_list,
- FALSE);
- match = libbalsa_utf8_strstr(str,cond->match.string.string);
- g_free(str);
- if (match) break;
+ if (message->headers->cc_list) {
+ gchar *str =
+ internet_address_list_to_string(message->headers->
+ cc_list, FALSE);
+ match =
+ libbalsa_utf8_strstr(str, cond->match.string.string);
+ g_free(str);
+ if (match)
+ break;
+ }
}
if (CONDITION_CHKMATCH(cond,CONDITION_MATCH_US_HEAD)) {
if (cond->match.string.user_header) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]