Mark Stosberg <[EMAIL PROTECTED]> writes:

> Every few days now I've been getting spam that crashes tmda-pending.

I've now fixed this in CVS.  Apply the attached patch to your 'TMDA'
lib directory or wait until TMDA 0.81 is released.

> Thinking in Perl terms, the solution would be wrap this part of the
> code in an "eval" statement, so even if the parser died,
> tmda-pending could die more gracefully, and just skip the message
> with a note that it's unparsable.

I've done something similar; I just display the header as a raw string
if it can't be decoded instead of throwing the exception.

Thanks.
Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.99
diff -u -r1.99 Util.py
--- Util.py	1 Jul 2003 06:29:51 -0000	1.99
+++ Util.py	9 Jul 2003 18:20:37 -0000
@@ -569,20 +569,23 @@
 
 def decode_header(str):
     """Accept a possibly encoded message header as a string, and
-    return a decoded string.
+    return a decoded string if it can be decoded.
 
     JRM: email.Header has a decode_header method, but it returns a
     list of decoded pairs, one for each part of the header, which is
     an awkward interface IMO, especially when the header contains a
     mix of encoded and non-encoded parts.
     """
-    from email import Header
-    parts = []
-    pairs = Header.decode_header(str)
-    for pair in pairs:
-        parts.append(pair[0])
-    decoded_string = ' '.join(parts)
-    return decoded_string
+    try:
+        from email import Header
+        parts = []
+        pairs = Header.decode_header(str)
+        for pair in pairs:
+            parts.append(pair[0])
+        decoded_string = ' '.join(parts)
+        return decoded_string
+    except email.Errors.HeaderParseError:
+        return str
 
 
 def headers_as_list(msg):

Reply via email to