aboutsummaryrefslogtreecommitdiff
path: root/src/filter.c
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-09-05 07:54:55 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-09-05 07:54:55 +0000
commit11776e5a524745b01ac145439ac2892a29bd0826 (patch)
tree233db0a019b3b533581f611edb9802a80d664279 /src/filter.c
parent51f886e4c8b44242b10c057a1af70f66f28bb2e6 (diff)
moved procmsg.c::procmsg_get_filter_keyword() to filter.c::filter_get_keyword_from_msg().
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@547 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'src/filter.c')
-rw-r--r--src/filter.c103
1 files changed, 102 insertions, 1 deletions
diff --git a/src/filter.c b/src/filter.c
index 8d85b95c..efc2fa02 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -34,8 +34,9 @@
#endif
#include <time.h>
-#include "procheader.h"
#include "filter.h"
+#include "procmsg.h"
+#include "procheader.h"
#include "folder.h"
#include "utils.h"
#include "xml.h"
@@ -1261,6 +1262,106 @@ void filter_rule_match_type_str_to_enum(const gchar *match_type,
}
}
+void filter_get_keyword_from_msg(MsgInfo *msginfo, gchar **header, gchar **key,
+ FilterCreateType type)
+{
+ static HeaderEntry hentry[] = {{"List-Id:", NULL, TRUE},
+ {"X-ML-Name:", NULL, TRUE},
+ {"X-List:", NULL, TRUE},
+ {"X-Mailing-list:", NULL, TRUE},
+ {"X-Sequence:", NULL, TRUE},
+ {NULL, NULL, FALSE}};
+ enum
+ {
+ H_LIST_ID = 0,
+ H_X_ML_NAME = 1,
+ H_X_LIST = 2,
+ H_X_MAILING_LIST = 3,
+ H_X_SEQUENCE = 4
+ };
+
+ FILE *fp;
+
+ g_return_if_fail(msginfo != NULL);
+ g_return_if_fail(header != NULL);
+ g_return_if_fail(key != NULL);
+
+ *header = NULL;
+ *key = NULL;
+
+ switch (type) {
+ case FLT_BY_NONE:
+ return;
+ case FLT_BY_AUTO:
+ if ((fp = procmsg_open_message(msginfo)) == NULL)
+ return;
+ procheader_get_header_fields(fp, hentry);
+ fclose(fp);
+
+#define SET_FILTER_KEY(hstr, idx) \
+{ \
+ *header = g_strdup(hstr); \
+ *key = hentry[idx].body; \
+ hentry[idx].body = NULL; \
+}
+
+ if (hentry[H_LIST_ID].body != NULL) {
+ SET_FILTER_KEY("List-Id", H_LIST_ID);
+ extract_list_id_str(*key);
+ } else if (hentry[H_X_ML_NAME].body != NULL) {
+ SET_FILTER_KEY("X-ML-Name", H_X_ML_NAME);
+ } else if (hentry[H_X_LIST].body != NULL) {
+ SET_FILTER_KEY("X-List", H_X_LIST);
+ } else if (hentry[H_X_MAILING_LIST].body != NULL) {
+ SET_FILTER_KEY("X-Mailing-list", H_X_MAILING_LIST);
+ } else if (hentry[H_X_SEQUENCE].body != NULL) {
+ gchar *p;
+
+ SET_FILTER_KEY("X-Sequence", H_X_SEQUENCE);
+ p = *key;
+ while (*p != '\0') {
+ while (*p != '\0' && !g_ascii_isspace(*p)) p++;
+ while (g_ascii_isspace(*p)) p++;
+ if (g_ascii_isdigit(*p)) {
+ *p = '\0';
+ break;
+ }
+ }
+ g_strstrip(*key);
+ } else if (msginfo->subject) {
+ *header = g_strdup("Subject");
+ *key = g_strdup(msginfo->subject);
+ }
+
+#undef SET_FILTER_KEY
+
+ g_free(hentry[H_LIST_ID].body);
+ hentry[H_LIST_ID].body = NULL;
+ g_free(hentry[H_X_ML_NAME].body);
+ hentry[H_X_ML_NAME].body = NULL;
+ g_free(hentry[H_X_LIST].body);
+ hentry[H_X_LIST].body = NULL;
+ g_free(hentry[H_X_MAILING_LIST].body);
+ hentry[H_X_MAILING_LIST].body = NULL;
+
+ break;
+ case FLT_BY_FROM:
+ *header = g_strdup("From");
+ *key = g_strdup(msginfo->from);
+ break;
+ case FLT_BY_TO:
+ *header = g_strdup("To");
+ *key = g_strdup(msginfo->to);
+ break;
+ case FLT_BY_SUBJECT:
+ *header = g_strdup("Subject");
+ *key = g_strdup(msginfo->subject);
+ break;
+ default:
+ break;
+ }
+}
+
void filter_rule_list_free(GSList *fltlist)
{
GSList *cur;