On Wed, 25 Sep 2002 23:02:28 -0700 (Pacific Daylight Time) Michael A Chase 
<[EMAIL PROTECTED]> wrote:

Here's the patch I meant to attach to my previous message.
-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.
# 
# 
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'patch' program with this file as input.
#
#### End of Preamble ####

#### Patch data follows ####
diff -ub 'M/include/MFilter.h' 'M-641/include/MFilter.h'
Index: ./include/MFilter.h
Prereq:  1.14 
--- ./include/MFilter.h Mon Sep  9 19:21:18 2002
+++ ./include/MFilter.h Tue Sep 24 19:22:47 2002
@@ -45,6 +45,7 @@
    ORC_T_ScoreAbove,       // score of the message is greater than argument
    ORC_T_ScoreBelow,       //                         less
    ORC_T_IsToMe,           // the message is addressed to one of my addresses
+   ORC_T_FlagSet,          // flag set for message
    ORC_T_Illegal,          // illegal must not occur
    ORC_T_Max = ORC_T_Illegal
 };
@@ -73,10 +74,13 @@
    OAC_T_MessageBox,
    OAC_T_LogEntry,
    OAC_T_Python,
-   OAC_T_ChangeScore,
+   OAC_T_AddScore,
    OAC_T_SetColour,
    OAC_T_Zap,
    OAC_T_Print,
+   OAC_T_SetFlag,
+   OAC_T_ClearFlag,
+   OAC_T_SetScore,
    OAC_T_Max
 };
 
@@ -94,6 +98,9 @@
 /// return true if this filter test requires the target to operate on
 extern bool FilterTestNeedsTarget(int test);
 
+/// return true if this filter test is not being used
+extern bool FilterTestNotUsed(int test);
+
 //@}
 
 /** This is a set of dialog settings representing a filter rule. A
diff -ub 'M/src/classes/MFilter.cpp' 'M-641/src/classes/MFilter.cpp'
Index: ./src/classes/MFilter.cpp
Prereq:  1.22 
--- ./src/classes/MFilter.cpp   Mon Sep  9 19:21:29 2002
+++ ./src/classes/MFilter.cpp   Wed Sep 25 22:51:38 2002
@@ -147,12 +147,14 @@
    "score() > ",        // ORC_T_ScoreAbove
    "score() < ",        // ORC_T_ScoreBelow
    "istome()",          // ORC_T_IsToMe
+   "flag(",             // ORC_T_FlagSet
    NULL
 };
 
 /// this array tells us if the tests need arguments
 #define ORC_F_NeedsTarget   0x01
 #define ORC_F_NeedsArg      0x02
+#define ORC_F_Unimplemented 0x80
 
 static unsigned char ORC_T_Flags[] =
 {
@@ -167,11 +169,21 @@
    ORC_F_NeedsArg,                     // ORC_T_OlderThan,
    ORC_F_NeedsArg,                     // ORC_T_NewerThan,
    ORC_F_NeedsArg,                     // ORC_T_IsSpam,
+#ifndef USE_PYTHON
+   ORC_F_Unimplemented|
+#endif
    ORC_F_NeedsArg,                     // ORC_T_Python,
    ORC_F_NeedsTarget|ORC_F_NeedsArg,   // ORC_T_MatchRegEx,
+#ifndef USE_HEADER_SCORE
+   ORC_F_Unimplemented|
+#endif
    ORC_F_NeedsArg,                     // ORC_T_ScoreAbove,
+#ifndef USE_HEADER_SCORE
+   ORC_F_Unimplemented|
+#endif
    ORC_F_NeedsArg,                     // ORC_T_ScoreBelow
    0,                                  // ORC_T_IsToMe
+   ORC_F_NeedsArg,                     // ORC_T_FlagSet,
 };
 
 bool FilterTestNeedsArgument(int test)
@@ -190,50 +202,74 @@
    return (ORC_T_Flags[test] & ORC_F_NeedsTarget) != 0;
 }
 
+bool FilterTestUnimplemented(int test)
+{
+   CHECK( test >= 0 && (unsigned)test < WXSIZEOF(ORC_T_Flags), false,
+          _T("invalid filter test") );
+
+   return (ORC_T_Flags[test] & ORC_F_Unimplemented) != 0;
+}
+
 static
 const char * ORC_W_Names[] =
 {
-   "subject()",
-   "header()",
-   "from()",
-   "body()",
-   "message()",
-   "to()",
-   "header(\"Sender\")",
-   "recipients()",
+   "subject()",             // ORC_W_Subject
+   "header()",              // ORC_W_Header
+   "from()",                // ORC_W_From
+   "body()",                // ORC_W_Body
+   "message()",             // ORC_W_Message
+   "to()",                  // ORC_W_To
+   "header(\"Sender\")",    // ORC_W_Sender
+   "recipients()",          // ORC_W_Recipients
    NULL
 };
 
 static const char * OAC_T_Names[] =
 {
-   "delete(",
-   "copy(",
-   "move(",
-   "expunge(",
-   "message(",
-   "log(",
-   "python(",
-   "addscore(",
-   "setcolour(",
-   "zap(",
-   "print(",
+   "delete(",       // OAC_T_Delete
+   "copy(",         // OAC_T_CopyTo
+   "move(",         // OAC_T_MoveTo
+   "expunge(",      // OAC_T_Expunge
+   "message(",      // OAC_T_MessageBox
+   "log(",          // OAC_T_LogEntry
+   "python(",       // OAC_T_Python
+   "addscore(",     // OAC_T_AddScore
+   "setcolour(",    // OAC_T_SetColour
+   "zap(",          // OAC_T_Zap
+   "print(",        // OAC_T_Print
+   "setflag(",      // OAC_T_SetFlag
+   "clearflag(",    // OAC_T_ClearFlag
+   "setscore(",     // OAC_T_SetScore
    NULL
 };
 
 #define OAC_F_NeedsArg   0x01
+#define OAC_F_Unimplemented 0x80
 static unsigned char OAC_T_Flags[] =
 {
-   0,
-   OAC_F_NeedsArg,
-   OAC_F_NeedsArg,
-   0,
-   OAC_F_NeedsArg,
-   OAC_F_NeedsArg,
-   OAC_F_NeedsArg,
-   OAC_F_NeedsArg,
-   OAC_F_NeedsArg,
-   0,
-   0,
+   0,               // OAC_T_Delete
+   OAC_F_NeedsArg,  // OAC_T_CopyTo
+   OAC_F_NeedsArg,  // OAC_T_MoveTo
+   0,               // OAC_T_Expunge
+   OAC_F_NeedsArg,  // OAC_T_MessageBox
+   OAC_F_NeedsArg,  // OAC_T_LogEntry
+#ifndef USE_PYTHON
+   ORC_F_Unimplemented|
+#endif
+   OAC_F_NeedsArg,  // OAC_T_Python
+#ifndef USE_HEADER_SCORE
+   ORC_F_Unimplemented|
+#endif
+   OAC_F_NeedsArg,  // OAC_T_AddScore
+   OAC_F_NeedsArg,  // OAC_T_SetColour
+   0,               // OAC_T_Zap
+   0,               // OAC_T_Print
+   OAC_F_NeedsArg,  // OAC_T_SetFlag
+   OAC_F_NeedsArg,  // OAC_T_ClearFlag
+#ifdef USE_HEADER_SCORE
+   ORC_F_Unimplemented|
+#endif
+   OAC_F_NeedsArg,  // OAC_T_SetScore
 };
 
 wxCOMPILE_TIME_ASSERT( WXSIZEOF(ORC_T_Names) == ORC_T_Max + 1,
diff -ub 'M/src/gui/wxFiltersDialog.cpp' 'M-641/src/gui/wxFiltersDialog.cpp'
Index: ./src/gui/wxFiltersDialog.cpp
Prereq:  1.99 
--- ./src/gui/wxFiltersDialog.cpp       Mon Sep 16 14:45:26 2002
+++ ./src/gui/wxFiltersDialog.cpp       Tue Sep 24 20:15:53 2002
@@ -103,22 +103,32 @@
 static const
 wxString ORC_Types[] =
 {
-   gettext_noop("Always"),
-   gettext_noop("Match"),
-   gettext_noop("Contains"),
-   gettext_noop("Match Case"),
-   gettext_noop("Contains Case"),
-   gettext_noop("Match RegExp Case"),
-   gettext_noop("Larger than"),
-   gettext_noop("Smaller than"),
-   gettext_noop("Older than"),
-   gettext_noop("Newer than"),
-   gettext_noop("Seems to be SPAM"),
-   gettext_noop("Python"),
-   gettext_noop("Match RegExp"),
-   gettext_noop("Score above"),
-   gettext_noop("Score below"),
-   gettext_noop("Sent to me"),
+   gettext_noop("Always"),              // ORC_T_Always
+   gettext_noop("Match"),               // ORC_T_Match
+   gettext_noop("Contains"),            // ORC_T_Contains
+   gettext_noop("Match Case"),          // ORC_T_MatchC
+   gettext_noop("Contains Case"),       // ORC_T_ContainsC
+   gettext_noop("Match RegExp Case"),   // ORC_T_MatchRegExC
+   gettext_noop("Larger than"),         // ORC_T_LargerThan
+   gettext_noop("Smaller than"),        // ORC_T_SmallerThan
+   gettext_noop("Older than"),          // ORC_T_OlderThan
+   gettext_noop("Newer than"),          // ORC_T_NewerThan
+   gettext_noop("Seems to be SPAM"),    // ORC_T_IsSpam
+#ifdef USE_PYTHON
+   gettext_noop("Python"),              // ORC_T_Python
+#else
+   "",
+#endif
+   gettext_noop("Match RegExp"),        // ORC_T_MatchRegEx
+#ifdef USE_HEADER_SCORE
+   gettext_noop("Score above"),         // ORC_T_ScoreAbove
+   gettext_noop("Score below"),         // ORC_T_ScoreBelow
+#else
+   "",
+   "",
+#endif
+   gettext_noop("Sent to me"),          // ORC_T_IsToMe
+   gettext_noop("Flag Set"),            // ORC_T_FlagSet
 };
 
 static const size_t ORC_TypesCount = WXSIZEOF(ORC_Types);
@@ -126,14 +136,14 @@
 static const
 wxString ORC_Where[] =
 {
-   gettext_noop("in subject"),
-   gettext_noop("in header"),
-   gettext_noop("in from"),
-   gettext_noop("in body"),
-   gettext_noop("in message"),
-   gettext_noop("in to"),
-   gettext_noop("in sender"),
-   gettext_noop("in any recipient")
+   gettext_noop("in subject"),          // ORC_W_Subject
+   gettext_noop("in header"),           // ORC_W_Header
+   gettext_noop("in from"),             // ORC_W_From
+   gettext_noop("in body"),             // ORC_W_Body
+   gettext_noop("in message"),          // ORC_W_Message
+   gettext_noop("in to"),               // ORC_W_To
+   gettext_noop("in sender"),           // ORC_W_Sender
+   gettext_noop("in any recipient")     // ORC_W_Recipients
 };
 
 static const
@@ -142,8 +152,8 @@
 static const
 wxString ORC_Logical[] =
 {
-   gettext_noop("or"),
-   gettext_noop("and"),
+   gettext_noop("or"),  // ORC_L_Or
+   gettext_noop("and"), // ORC_L_And
 };
 
 static const
@@ -154,17 +164,32 @@
 static const
 wxString OAC_Types[] =
 {
-   gettext_noop("Delete"),
-   gettext_noop("Copy to"),
-   gettext_noop("Move to"),
-   gettext_noop("Expunge"),
-   gettext_noop("MessageBox"),
-   gettext_noop("Log Entry"),
-   gettext_noop("Python"),
-   gettext_noop("Change Score"),
-   gettext_noop("Set Colour"),
-   gettext_noop("Zap"),
-   gettext_noop("Print")
+   gettext_noop("Delete"),              // OAC_T_Delete
+   gettext_noop("Copy to"),             // OAC_T_CopyTo
+   gettext_noop("Move to"),             // OAC_T_MoveTo
+   gettext_noop("Expunge"),             // OAC_T_Expunge
+   gettext_noop("MessageBox"),          // OAC_T_MessageBox
+   gettext_noop("Log Entry"),           // OAC_T_LogEntry
+#ifdef USE_PYTHON
+   gettext_noop("Python"),              // OAC_T_Python
+#else
+   "",
+#endif
+#ifdef USE_HEADER_SCORE
+   gettext_noop("Change Score"),        // OAC_T_AddScore
+#else
+   "",
+#endif
+   gettext_noop("Set Colour"),          // OAC_T_SetColour
+   gettext_noop("Zap"),                 // OAC_T_Zap
+   gettext_noop("Print")                // OAC_T_Print
+   gettext_noop("Set Flag"),            // OAC_T_SetFlag
+   gettext_noop("Clear Flag"),          // OAC_T_ClearFlag
+#ifdef USE_HEADER_SCORE
+   gettext_noop("Set Score"),           // OAC_T_SetScore
+#else
+   "",
+#endif
 };
 
 static const
@@ -762,6 +787,7 @@
             wxLogDebug(_T("Unknown spam test \"%s\""), t.c_str());
       }
    }
+
 }
 
 void
@@ -961,7 +987,7 @@
    m_btnFolder = new wxFolderBrowseButton(m_Argument, parent);
    m_btnColour = new wxColorBrowseButton(m_Argument, parent);
 
-   // select something or UpdateProgram() would complain abotu invalid action
+   // select something or UpdateProgram() would complain about invalid action
    m_Type->Select(OAC_T_Delete);
 }
 
diff -ub 'M/src/modules/Filters.cpp' 'M-641/src/modules/Filters.cpp'
Index: ./src/modules/Filters.cpp
Prereq:  1.135 
--- ./src/modules/Filters.cpp   Wed Sep 25 18:02:36 2002
+++ ./src/modules/Filters.cpp   Wed Sep 25 22:46:53 2002
@@ -2489,6 +2489,35 @@
    return Value(false);
 }
 
+static Value func_flagset(ArgList *args, FilterRuleImpl *p)
+{
+   if(args->Count() != 1)
+      return Value(false);
+   const Value v1 = args->GetArg(0)->Evaluate();
+   String flag_str = v1.ToString();
+   if(flag_str.Length() != 1)
+      return Value(false);
+   Message_obj msg = p->GetMessage();
+   if(! msg)
+      return Value(false);
+   int status = msg->GetStatus();
+
+   if ( flag_str == "U" )        // Unread (result is inverted)
+      return Value(status & MailFolder::MSG_STAT_SEEN     ? false : true);
+   else if ( flag_str == "D" )   // Deleted
+      return Value(status & MailFolder::MSG_STAT_DELETED  ? true  : false);
+   else if ( flag_str == "A" )   // Answered
+      return Value(status & MailFolder::MSG_STAT_ANSWERED ? true  : false);
+   else if ( flag_str == "R" )   // Recent
+      return Value(status & MailFolder::MSG_STAT_RECENT   ? true  : false);
+   else if ( flag_str == "S" )   // Search match
+      return Value(status & MailFolder::MSG_STAT_SEARCHED ? true  : false);
+   else if ( flag_str == "*" )   // Flagged/Important
+      return Value(status & MailFolder::MSG_STAT_FLAGGED  ? true  : false);
+
+   return Value(false);
+}
+
 static Value func_header(ArgList *args, FilterRuleImpl *p)
 {
    if(args->Count() != 0)
@@ -2648,6 +2677,35 @@
    return Value(score);
 }
 
+static Value func_setscore(ArgList *args, FilterRuleImpl *p)
+{
+   if(args->Count() != 1)
+      return Value(-1);
+
+   const Value d = args->GetArg(0)->Evaluate();
+
+#ifdef USE_HEADER_SCORE
+   MailFolder_obj mf = p->GetFolder();
+   if ( mf )
+   {
+      HeaderInfoList_obj hil = mf->GetHeaders();
+      if(hil)
+      {
+         Message_obj msg = p->GetMessage();
+         if ( msg )
+         {
+            // MAC: I'd rather use ->SetScore() or something similar,
+            // MAC: but I couldn't find any of the scoring methods.
+            int score = hil->GetEntryUId( msg->GetUId() )->GetScore();
+            hil->GetEntryUId( msg->GetUId() )->AddScore(d.ToNumber() - score);
+         }
+      }
+   }
+#endif // USE_HEADER_SCORE
+
+   return Value(0);
+}
+
 static Value func_addscore(ArgList *args, FilterRuleImpl *p)
 {
    if(args->Count() != 1)
@@ -2673,6 +2731,7 @@
 
    return Value(0);
 }
+
 static Value func_setcolour(ArgList *args, FilterRuleImpl *p)
 {
    if(args->Count() != 1)
@@ -2699,6 +2758,52 @@
    return Value(0);
 }
 
+static Value func_do_setflag(ArgList *args, FilterRuleImpl *p, bool set)
+{
+   if(args->Count() != 1)
+      return Value(false);
+   const Value v1 = args->GetArg(0)->Evaluate();
+   String flag_str = v1.ToString();
+   if(flag_str.Length() != 1)
+      return Value(false);
+
+   int flag = 0;
+   if ( flag_str == "U" )        // Unread, inverse of actual flag (SEEN)
+   {
+      flag = MailFolder::MSG_STAT_SEEN;
+      set  = ! set;
+   }
+   else if ( flag_str == "D" )   // Deleted
+      flag = MailFolder::MSG_STAT_DELETED;
+   else if ( flag_str == "A" )   // Answered
+      flag = MailFolder::MSG_STAT_ANSWERED;
+   // The Recent flag is not changable.
+   // else if ( flag_str == "R" )   // Recent
+   //   flag = MailFolder::MSG_STAT_RECENT;
+   else if ( flag_str == "S" )   // Search match
+      flag = MailFolder::MSG_STAT_SEARCHED;
+   else if ( flag_str == "*" )   // Flagged/Important
+      flag = MailFolder::MSG_STAT_FLAGGED;
+   else
+      return Value(false);
+
+   // Set or clear the selected flag
+   MailFolder_obj mf = p->GetFolder();
+   if ( ! mf )
+      return Value(false);
+   return Value(mf->SetMessageFlag(p->GetMessageUId(), flag, set));
+}
+
+static Value func_setflag(ArgList *args, FilterRuleImpl *p)
+{
+   return func_do_setflag(args, p, true);
+}
+
+static Value func_clearflag(ArgList *args, FilterRuleImpl *p)
+{
+   return func_do_setflag(args, p, false);
+}
+
 
 /* * * * * * * * * * * * * * *
 *
@@ -2756,6 +2861,7 @@
          Define("recipients", func_recipients);
          Define("headerline", func_headerline);
          Define("from", func_from);
+         Define("flagset", func_flagset);
          Define("header", func_header);
          Define("body", func_body);
          Define("text", func_text);
@@ -2773,8 +2879,11 @@
          Define("matchregexi", func_matchregexi);
          Define("setcolour", func_setcolour);
          Define("score", func_score);
+         Define("setscore", func_setscore);
          Define("addscore", func_addscore);
          Define("istome", func_istome);
+         Define("setflag", func_setflag);
+         Define("clearflag", func_clearflag);
 #ifdef TEST
          Define("nargs", func_nargs);
          Define("arg", func_arg);
#### End of Patch data ####

#### ApplyPatch data follows ####
# Data version        : 1.0
# Date generated      : Wed Sep 25 22:51:47 2002
# Generated by        : makepatch 2.00_09*
# Recurse directories : Yes
# Excluded files      : (\A|/).*\~\Z
#                       (\A|/).*\.a\Z
#                       (\A|/).*\.bak\Z
#                       (\A|/).*\.BAK\Z
#                       (\A|/).*\.elc\Z
#                       (\A|/).*\.exe\Z
#                       (\A|/).*\.gz\Z
#                       (\A|/).*\.ln\Z
#                       (\A|/).*\.o\Z
#                       (\A|/).*\.obj\Z
#                       (\A|/).*\.olb\Z
#                       (\A|/).*\.old\Z
#                       (\A|/).*\.orig\Z
#                       (\A|/).*\.rej\Z
#                       (\A|/).*\.so\Z
#                       (\A|/).*\.Z\Z
#                       (\A|/)\.del\-.*\Z
#                       (\A|/)\.make\.state\Z
#                       (\A|/)\.nse_depinfo\Z
#                       (\A|/)core\Z
#                       (\A|/)tags\Z
#                       (\A|/)TAGS\Z
#                       (\A|/)\.\#.*\Z
#                       (\A|/)\#.*\Z
#                       (\A|/)_\$.*\Z
#                       (\A|/).*\$\Z
#                       (\A|/)CVS\Z
#                       (\A|/)CVS\.adm\Z
#                       (\A|/)cvslog\..*\Z
#                       (\A|/)\,.*\Z
#                       (\A|/).*\,v\Z
#                       (\A|/)RCS\Z
#                       (\A|/)RCSLOG\Z
#                       (\A|/)p\..*\Z
#                       (\A|/)s\..*\Z
#                       (\A|/)SCCS\Z
# p 'include/MFilter.h' 8755 1032920567 0100644
# p 'src/classes/MFilter.cpp' 23669 1033019498 0100644
# p 'src/gui/wxFiltersDialog.cpp' 69838 1032923753 0100644
# p 'src/modules/Filters.cpp' 86656 1033019213 0100644
#### End of ApplyPatch data ####

#### End of Patch kit [created: Wed Sep 25 22:51:47 2002] ####
#### Patch checksum: 543 16869 18437 ####
#### Checksum: 561 17495 4546 ####

Reply via email to