Added support to test if a particular header is present or not.
authorFrederic Jolliton <frederic@jolliton.com>
Wed, 17 Nov 2004 14:19:55 +0000 (14:19 +0000)
committerFrederic Jolliton <frederic@jolliton.com>
Wed, 17 Nov 2004 14:19:55 +0000 (14:19 +0000)
* The 'present' match was added to test if a header is present
  in mail or not.

git-archimport-id: frederic@jolliton.com--2004-private/mail-filter--main--0.1.2--patch-2

confparser.py
mailfilter.py

index 859565b..d9b213b 100644 (file)
@@ -110,11 +110,17 @@ class Header( Validator ) :
 
        def check( self , values ) :
 
-               if len( values ) != 3 :
-                       error( 'header expect 3 arguments: HEADER-NAME MATCH-TYPE MATCH-ARGUMENT.' )
-               elif values[ 1 ] not in self.allowedMatches :
-                       error( '%r is not an allowed match type. Allowed matches type are: %r'
-                               % ( values[ 1 ] , self.allowedMatches ) )
+               if len( values ) == 2 :
+                       if values[ 1 ] != 'present' :
+                               error( 'Invalid keyword %r. Expected \'present\'.' % values[ 1 ] )
+               elif len( values ) == 3 :
+                       if values[ 1 ] not in self.allowedMatches :
+                               error( '%r is not an allowed match type. Allowed matches type are: %r'
+                                       % ( values[ 1 ] , self.allowedMatches ) )
+               else :
+                       error( '''header expect 2 or 3 arguments:
+HEADER-NAME MATCH-TYPE MATCH-ARGUMENT
+HEADER-NAME MATCH-FLAG''' )
 
 #-----------------------------------------------------------------------------
 
index 7f00a38..c661e37 100644 (file)
@@ -623,6 +623,16 @@ def testRule( rule ) :
                if g_mail == None :
                        return False
                args = rule[ 1 ]
+               if len( args ) == 2 :
+                       #
+                       # Test 'present'
+                       #
+                       headerName , matchType = args
+                       if matchType not in [ 'present' ] :
+                               logMessage( 'Unknown match type %r' % matchType )
+                               return False
+                       return ( g_mail.get( headerName ) != None )
+
                headerName , matchType , text = args
                text = normalizeBlank( text )
                if headerName.find( '.' ) != -1 :