/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999,2000 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2001 Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <string.h>
#include <strings.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <regex.h>
#include "intl.h"
#include "procheader.h"
g_return_val_if_fail(file != NULL, NULL);
if (!fltlist) return NULL;
- hlist = procheader_get_header_list(file);
+ hlist = procheader_get_header_list_from_file(file);
if (!hlist) return NULL;
for (cur = fltlist; cur != NULL; cur = cur->next) {
if (filter_match_condition(filter, hlist)) {
if (filter->action == FLT_NOTRECV) {
if (!dummy) {
- dummy = folder_item_new(NULL, NULL);
+ dummy = g_new0(FolderItem, 0);
dummy->path = g_strdup(FILTER_NOT_RECEIVE);
}
dest_folder = dummy;
} else
- dest_folder = folder_find_item_from_path
+ dest_folder = folder_find_item_from_identifier
(filter->dest);
break;
}
return strcasestr(haystack, needle) != NULL ? FALSE : TRUE;
}
+static gboolean strmatch_regex(const gchar *haystack, const gchar *needle)
+{
+ gint ret = 0;
+ regex_t preg;
+ regmatch_t pmatch[1];
+
+ ret = regcomp(&preg, needle, 0);
+ if (ret != 0) return FALSE;
+
+ ret = regexec(&preg, haystack, 1, pmatch, 0);
+ regfree(&preg);
+
+ if (ret == REG_NOMATCH) return FALSE;
+
+ if (pmatch[0].rm_so != -1)
+ return TRUE;
+ else
+ return FALSE;
+}
+
gboolean filter_match_condition(Filter *filter, GSList *hlist)
{
Header *header;
g_return_val_if_fail(filter->name1 != NULL, FALSE);
- if (FLT_IS_CASE_SENS(filter->flag1))
+ if (FLT_IS_REGEX(filter->flag1))
+ StrFind1 = strmatch_regex;
+ else if (FLT_IS_CASE_SENS(filter->flag1))
StrFind1 = FLT_IS_CONTAIN(filter->flag1)
? strfind : strnotfind;
else
StrFind1 = FLT_IS_CONTAIN(filter->flag1)
? strcasefind : strcasenotfind;
+ if (FLT_IS_REGEX(filter->flag2))
+ StrFind2 = strmatch_regex;
if (FLT_IS_CASE_SENS(filter->flag2))
StrFind2 = FLT_IS_CONTAIN(filter->flag2)
? strfind : strnotfind;
gchar *name1, *body1, *op, *name2, *body2, *dest;
gchar *flag1 = NULL, *flag2 = NULL, *action = NULL;
- Xalloca(tmp, strlen(str) + 1, return NULL);
- strcpy(tmp, str);
+ Xstrdup_a(tmp, str, return NULL);
name1 = tmp;
PARSE_ONE_PARAM(body1, name1);