CVS: tmda/TMDA Util.py,1.99,1.100

"Jason R. Mastaler" <[email protected]>
Newsgroups gmane.mail.spam.tmda.cvs
Message-ID <[email protected]>
Update of /cvsroot/tmda/tmda/TMDA
In directory sc8-pr-cvs1:/tmp/cvs-serv3560/TMDA

Modified Files:
	Util.py 
Log Message:
Bugfix.  If the header can't be decoded, just return the raw
string instead of throwing an email.Errors.HeaderParseError
exception.


Index: Util.py
===================================================================
RCS file: /cvsroot/tmda/tmda/TMDA/Util.py,v
retrieving revision 1.99
retrieving revision 1.100
diff -u -r1.99 -r1.100
--- Util.py	1 Jul 2003 06:29:51 -0000	1.99
+++ Util.py	9 Jul 2003 18:23:01 -0000	1.100
@@ -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):

_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.