From 870cb85fd0c92f216f92f18004f4ed98d0534e60 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Tue, 2 Jan 2007 21:53:44 +0000 Subject: [PATCH] Added both power and ease-of-use to the Match Header addon. A regular case-sensitive string search is done unless REGEX: appears at the beginning, in which case a full-blown regular expression search is done git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19683 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../inbound_filters/match_header/ConfigView.cpp | 4 ++-- .../inbound_filters/match_header/RuleFilter.cpp | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/add-ons/mail_daemon/inbound_filters/match_header/ConfigView.cpp b/src/add-ons/mail_daemon/inbound_filters/match_header/ConfigView.cpp index 8a53027810..b924729753 100644 --- a/src/add-ons/mail_daemon/inbound_filters/match_header/ConfigView.cpp +++ b/src/add-ons/mail_daemon/inbound_filters/match_header/ConfigView.cpp @@ -50,8 +50,8 @@ RuleFilterConfig::RuleFilterConfig(BMessage *settings) : BView(BRect(0,0,260,85) attr->SetText(settings->FindString("attribute")); AddChild(attr); - regex = new BTextControl(BRect(104,5,255,20),"attr",MDR_DIALECT_CHOICE (" is "," が "),MDR_DIALECT_CHOICE ("value (can be a regular expression, like *spam*)","値(正規表現対応)"),NULL); - regex->SetDivider(be_plain_font->StringWidth(MDR_DIALECT_CHOICE (" is "," が ")) + 4); + regex = new BTextControl(BRect(104,5,255,20),"attr",MDR_DIALECT_CHOICE (" has "," が "),MDR_DIALECT_CHOICE ("value (use REGEX: in from of regular expressions like *spam*)","値(正規表現対応)"),NULL); + regex->SetDivider(be_plain_font->StringWidth(MDR_DIALECT_CHOICE (" has "," が ")) + 4); if (settings->HasString("regex")) regex->SetText(settings->FindString("regex")); AddChild(regex); diff --git a/src/add-ons/mail_daemon/inbound_filters/match_header/RuleFilter.cpp b/src/add-ons/mail_daemon/inbound_filters/match_header/RuleFilter.cpp index 0b4d0b5e71..6f26a4a85f 100644 --- a/src/add-ons/mail_daemon/inbound_filters/match_header/RuleFilter.cpp +++ b/src/add-ons/mail_daemon/inbound_filters/match_header/RuleFilter.cpp @@ -21,9 +21,16 @@ RuleFilter::RuleFilter(BMessage *settings) : BMailFilter(settings) { attr.CapitalizeEachWord(); attribute = strdup(attr.String()); - const char *regex = NULL; + BString regex; settings->FindString("regex",®ex); - matcher.SetPattern(regex,true); + + int32 index = regex.FindFirst("REGEX:"); + if (index == B_ERROR || index > 0) + EscapeRegexTokens(regex); + else + regex.RemoveFirst("REGEX:"); + + matcher.SetPattern(regex.String(),false); settings->FindString("argument",&arg); settings->FindInt32("do_what",(long *)&do_what); @@ -59,10 +66,10 @@ status_t RuleFilter::ProcessMailMessage if (data == NULL) //--- How would this happen? No idea return B_OK; - + if (!matcher.Match(data)) return B_OK; //-----There wasn't an error. We're just not supposed to do anything - + switch (do_what) { case Z_MOVE_TO: if (io_headers->ReplaceString("DESTINATION",arg) != B_OK)