* 'broken' test, in addition to testing that the mail was
correctly parsed by email python module, now also test
that every header can be decoded correctly (that mean
that for example, a subject header with 8 bits contents
will be marked as broken.)
git-archimport-id: frederic@jolliton.com--2004-private/mail-filter--main--0.1.2--patch-4
logMessage( 'Error decoding %r' % s )
return s
+def isMailBroken() :
+
+ if g_mail == None :
+ return True
+ brokenHeaders = []
+ for headerName , headerContents in g_mail.items() :
+ try :
+ for text , charset in email.Header.decode_header( headerContents ) :
+ text.decode( charset or 'ascii' )
+ except UnicodeDecodeError , e :
+ brokenHeaders.append( headerName )
+ if brokenHeaders :
+ logMessage( 'The following headers are broken: %r' % brokenHeaders )
+ return True
+ return False
+
#
# Test rule 'rule' against the mail.
#
# Broken mail
#
if cmd == 'broken' :
- return g_mail == None
+ return g_mail == None or isMailBroken()
#
# Infected mail