Update of /cvsroot/mahogany/M/src/modules
In directory usw-pr-cvs1:/tmp/cvs-serv15623/src/modules

Modified Files:
        Filters.cpp 
Log Message:
added more anti-spam filter tests


Index: Filters.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/Filters.cpp,v
retrieving revision 1.111
retrieving revision 1.112
diff -b -u -2 -r1.111 -r1.112
--- Filters.cpp 17 Mar 2002 21:22:48 -0000      1.111
+++ Filters.cpp 18 Jun 2002 14:48:13 -0000      1.112
@@ -59,6 +59,10 @@
 static const char *headersRecipients[] =
 {
-   "To", "CC", "Bcc",
-   "Resent-To", "Resent-Cc", "Resent-Bcc",
+   "To",
+   "CC",
+   "Bcc",
+   "Resent-To",
+   "Resent-Cc",
+   "Resent-Bcc",
    NULL
 };
@@ -1864,38 +1868,64 @@
 {
    // standard check:
-   if(args->Count() != 0) return Value("");
+   if(args->Count() != 0)
+      return Value("");
 
    bool rc = false;
+
+   Message_obj msg = p->GetMessage();
+   if ( msg )
+   {
 #ifdef USE_RBL
-   String received;
+      String value;
 
-   Message * msg = p->GetMessage();
-   if(! msg) return Value(0);
-   msg->GetHeaderLine("Received", received);
-   msg->DecRef();
+      msg->GetHeaderLine("Received", value);
 
    int a,b,c,d;
-   String testHeader = received;
+      String testHeader = value;
 
-   while( (!rc) && (testHeader.Length() > 0) )
+      while ( !rc && !testHeader.empty() )
    {
       if(findIP(testHeader, '(', ')', &a, &b, &c, &d))
       {
-         for(int i = 0; gs_RblSites[i] && ! rc ; ++i)
-            rc |= CheckRBL(a,b,c,d,gs_RblSites[i]);
+            for ( int i = 0; gs_RblSites[i]; ++i )
+            {
+               if ( CheckRBL(a,b,c,d,gs_RblSites[i]) )
+               {
+                  rc = true;
+                  break;
+               }
+            }
       }
    }
-   testHeader = received;
-   while( (!rc) && (testHeader.Length() > 0) )
+
+      if ( !rc )
+      {
+         testHeader = value;
+         while ( !rc && !testHeader.empty() )
    {
       if(findIP(testHeader, '[', ']', &a, &b, &c, &d))
       {
-         for(int i = 0; gs_RblSites[i] && ! rc ; ++i)
-            rc |= CheckRBL(a,b,c,d,gs_RblSites[i]);
+               for ( int i = 0; gs_RblSites[i] ; ++i )
+               {
+                  if ( CheckRBL(a,b,c,d,gs_RblSites[i]) )
+                  {
+                     rc = true;
+                     break;
+                  }
+               }
+            }
       }
    }
 
    /*FIXME: if it is a hostname, maybe do a DNS lookup first? */
-#endif
+
+      if ( !rc )
+#endif // USE_RBL
+      {
+         // consider that only spams have this header
+         rc = msg->GetHeaderLine("X-Authentication-Warning", value);
+      }
+   }
+
    return rc;
 }
@@ -2006,4 +2036,32 @@
 }
 
+static Value func_subj8bit(ArgList *args, FilterRuleImpl *p)
+{
+   if(args->Count() != 0)
+      return Value(false);
+
+   Message_obj msg = p->GetMessage();
+   if(! msg)
+      return Value(false);
+
+   // consider that the subject is 8 bit if it contains more than half of 8 bit
+   // chars
+   String subject = msg->Subject();
+   size_t num8bit = 0,
+          max8bit = subject.length() / 2;
+   for ( const unsigned char *p = (unsigned char *)subject.c_str(); *p; p++ )
+   {
+      if ( *p > 127 )
+      {
+         if ( num8bit++ == max8bit )
+         {
+            return Value(true);
+         }
+      }
+   }
+
+   return Value(false);
+}
+
 #ifdef USE_PYTHON
 static Value func_python(ArgList *args, FilterRuleImpl *p)
@@ -2127,4 +2185,37 @@
 }
 
+static Value func_istome(ArgList *args, FilterRuleImpl *p)
+{
+   Value value = func_recipients(args, p);
+
+   MailFolder_obj mf = p->GetFolder();
+   if ( !mf )
+      return Value(false);
+
+   if ( p->GetInterface()->contains_own_address(value.GetString(),
+                                                mf->GetProfile()) )
+   {
+      return Value(true);
+   }
+
+   // check for List-Id header: this would mean that this message has been sent
+   // to a mailing list and so we should let it pass (of course, a smart
+   // spammer could always add a bogus List-Id but for now I didn't see this
+   // happen)
+   Message_obj msg = p->GetMessage();
+
+   if ( msg )
+   {
+      String value;
+      if ( msg->GetHeaderLine("List-Post", value) )
+      {
+         return Value(true);
+      }
+   }
+
+   // this message doesn't seem to be addresses to us
+   return Value(false);
+}
+
 static Value func_header(ArgList *args, FilterRuleImpl *p)
 {
@@ -2265,15 +2356,22 @@
    if(args->Count() != 0)
       return Value(0);
+
    int score = 0;
-   Message *msg = p->GetMessage();
-   HeaderInfoList *hil = p->GetFolder()->GetHeaders();
+#ifdef USE_HEADER_SCORE
+   MailFolder_obj mf = p->GetFolder();
+   if ( mf )
+   {
+      HeaderInfoList_obj hil = mf->GetHeaders();
    if(hil)
    {
-#ifdef USE_HEADER_SCORE
+         Message_obj msg = p->GetMessage();
+         if ( msg )
+         {
       score = hil->GetEntryUId( msg->GetUId() )->GetScore();
-#endif
-      hil->DecRef();
    }
-   msg->DecRef();
+      }
+   }
+#endif // USE_HEADER_SCORE
+
    return Value(score);
 }
@@ -2283,15 +2381,23 @@
    if(args->Count() != 1)
       return Value(-1);
+
    const Value d = args->GetArg(0)->Evaluate();
-   Message *msg = p->GetMessage();
-   HeaderInfoList *hil = p->GetFolder()->GetHeaders();
+
+#ifdef USE_HEADER_SCORE
+   MailFolder_obj mf = p->GetFolder();
+   if ( mf )
+   {
+      HeaderInfoList_obj hil = mf->GetHeaders();
    if(hil)
    {
-#ifdef USE_HEADER_SCORE
+         Message_obj msg = p->GetMessage();
+         if ( msg )
+         {
       hil->GetEntryUId( msg->GetUId() )->AddScore(d.ToNumber());
-#endif
-      hil->DecRef();
    }
-   msg->DecRef();
+      }
+   }
+#endif // USE_HEADER_SCORE
+
    return Value(0);
 }
@@ -2300,16 +2406,23 @@
    if(args->Count() != 1)
       return Value(-1);
+
+#ifdef USE_HEADER_COLOUR
    const Value c = args->GetArg(0)->Evaluate();
    String col = c.ToString();
-   Message *msg = p->GetMessage();
-   HeaderInfoList *hil = p->GetFolder()->GetHeaders();
+   MailFolder_obj mf = p->GetFolder();
+   if ( mf )
+   {
+      HeaderInfoList_obj hil = mf->GetHeaders();
    if(hil)
    {
-#ifdef USE_HEADER_COLOUR
+         Message_obj msg = p->GetMessage();
+         if ( msg )
+         {
       hil->GetEntryUId( msg->GetUId() )->SetColour(col);
-#endif
-      hil->DecRef();
    }
-   msg->DecRef();
+      }
+   }
+#endif // USE_HEADER_COLOUR
+
    return Value(0);
 }
@@ -2390,4 +2503,6 @@
          Define("score", func_score);
          Define("addscore", func_addscore);
+         Define("istome", func_istome);
+         Define("subj8bit", func_subj8bit);
 #ifdef TEST
          Define("nargs", func_nargs);


----------------------------------------------------------------------------
                   Bringing you mounds of caffeinated joy
                      >>>     http://thinkgeek.com/sf    <<<

_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to