aboutsummaryrefslogtreecommitdiff
path: root/libsylph
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-12-09 08:52:09 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-12-09 08:52:09 +0000
commit4966287d56be3f724ef0c31030baa4db29aeb72b (patch)
tree487f6e159d5d3cbd5b44c4a30bb2dc91c9cbc60f /libsylph
parentad59740f15a44999e3da126c49bdca09d8b7a61b (diff)
added utility functions for optimization of filter.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@814 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r--libsylph/filter.c23
-rw-r--r--libsylph/filter.h2
-rw-r--r--libsylph/procheader.c26
-rw-r--r--libsylph/procheader.h1
4 files changed, 52 insertions, 0 deletions
diff --git a/libsylph/filter.c b/libsylph/filter.c
index d4acc6a7..a7533bcc 100644
--- a/libsylph/filter.c
+++ b/libsylph/filter.c
@@ -440,6 +440,29 @@ static gboolean filter_match_header_cond(FilterCond *cond, GSList *hlist)
return matched;
}
+gboolean filter_rule_requires_full_headers(FilterRule *rule)
+{
+ GSList *cur;
+
+ for (cur = rule->cond_list; cur != NULL; cur = cur->next) {
+ FilterCond *cond = (FilterCond *)cur->data;
+ const gchar *name = cond->header_name;
+
+ if (cond->type == FLT_COND_HEADER && name) {
+ if (g_ascii_strcasecmp(name, "Date") != 0 &&
+ g_ascii_strcasecmp(name, "From") != 0 &&
+ g_ascii_strcasecmp(name, "To") != 0 &&
+ g_ascii_strcasecmp(name, "Newsgroups") != 0 &&
+ g_ascii_strcasecmp(name, "Subject") != 0)
+ return TRUE;
+ } else if (cond->type == FLT_COND_ANY_HEADER ||
+ cond->type == FLT_COND_TO_OR_CC)
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
#define RETURN_IF_TAG_NOT_MATCH(tag_name) \
if (strcmp2(xmlnode->tag->tag, tag_name) != 0) { \
g_warning("tag name != \"" tag_name "\"\n"); \
diff --git a/libsylph/filter.h b/libsylph/filter.h
index 1c040b7a..637991e6 100644
--- a/libsylph/filter.h
+++ b/libsylph/filter.h
@@ -163,6 +163,8 @@ gboolean filter_match_rule (FilterRule *rule,
GSList *hlist,
FilterInfo *fltinfo);
+gboolean filter_rule_requires_full_headers (FilterRule *rule);
+
/* read / write config */
GSList *filter_xml_node_to_filter_list (GNode *node);
void filter_read_config (void);
diff --git a/libsylph/procheader.c b/libsylph/procheader.c
index e175a8d6..cf9d481e 100644
--- a/libsylph/procheader.c
+++ b/libsylph/procheader.c
@@ -252,6 +252,32 @@ GSList *procheader_get_header_list(FILE *fp)
return hlist;
}
+GSList *procheader_get_header_list_from_msginfo(MsgInfo *msginfo)
+{
+ GSList *hlist = NULL;
+
+ g_return_val_if_fail(msginfo != NULL, NULL);
+
+ if (msginfo->subject)
+ hlist = procheader_add_header_list(hlist, "Subject",
+ msginfo->subject);
+ if (msginfo->from)
+ hlist = procheader_add_header_list(hlist, "From",
+ msginfo->from);
+ if (msginfo->to)
+ hlist = procheader_add_header_list(hlist, "To", msginfo->to);
+ if (msginfo->cc)
+ hlist = procheader_add_header_list(hlist, "Cc", msginfo->cc);
+ if (msginfo->newsgroups)
+ hlist = procheader_add_header_list(hlist, "Newsgroups",
+ msginfo->newsgroups);
+ if (msginfo->date)
+ hlist = procheader_add_header_list(hlist, "Date",
+ msginfo->date);
+
+ return hlist;
+}
+
GSList *procheader_add_header_list(GSList *hlist, const gchar *header_name,
const gchar *body)
{
diff --git a/libsylph/procheader.h b/libsylph/procheader.h
index d6c0a488..60a0abc0 100644
--- a/libsylph/procheader.h
+++ b/libsylph/procheader.h
@@ -52,6 +52,7 @@ gchar *procheader_get_unfolded_line (gchar *buf,
GSList *procheader_get_header_list_from_file (const gchar *file);
GSList *procheader_get_header_list (FILE *fp);
+GSList *procheader_get_header_list_from_msginfo (MsgInfo *msginfo);
GSList *procheader_add_header_list (GSList *hlist,
const gchar *header_name,
const gchar *body);