handle mail with bad charset
darcs-hash:20060302204557-86b55-21eff08ec557474d80642547bac4f1193d049c5e.gz
This commit is contained in:
@@ -200,27 +200,28 @@ class MailConnection(object):
|
|||||||
|
|
||||||
def get_decoded_part(self, part, charset_hint):
|
def get_decoded_part(self, part, charset_hint):
|
||||||
content_charset = part.get_content_charset()
|
content_charset = part.get_content_charset()
|
||||||
if content_charset:
|
result = u""
|
||||||
return unicode(part.get_payload(decode=True).decode(content_charset))
|
try:
|
||||||
else:
|
if content_charset:
|
||||||
result = ""
|
result = unicode(part.get_payload(decode=True).decode(content_charset))
|
||||||
try:
|
else:
|
||||||
result = unicode(part.get_payload(decode=True))
|
result = unicode(part.get_payload(decode=True))
|
||||||
|
except Exception, e:
|
||||||
|
try:
|
||||||
|
result = unicode(part.get_payload(decode=True).decode("iso-8859-1"))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
try:
|
try:
|
||||||
result = unicode(part.get_payload(decode=True).decode("iso-8859-1"))
|
result = unicode(part.get_payload(decode=True).decode(default_encoding))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
try:
|
if charset_hint is not None:
|
||||||
result = unicode(part.get_payload(decode=True).decode(default_encoding))
|
try:
|
||||||
except Exception, e:
|
result = unicode(part.get_payload(decode=True).decode(charset_hint))
|
||||||
if charset_hint is not None:
|
except Exception, e:
|
||||||
try:
|
type, value, stack = sys.exc_info()
|
||||||
result = unicode(part.get_payload(decode=True).decode(charset_hint))
|
print >>sys.stderr, "".join(traceback.format_exception
|
||||||
except Exception, e:
|
(type, value, stack, 5))
|
||||||
type, value, stack = sys.exc_info()
|
|
||||||
print >>sys.stderr, "".join(traceback.format_exception
|
return result
|
||||||
(type, value, stack, 5))
|
|
||||||
return result
|
|
||||||
|
|
||||||
def format_message(self, email_msg, include_body = True):
|
def format_message(self, email_msg, include_body = True):
|
||||||
from_decoded = email.Header.decode_header(email_msg["From"])
|
from_decoded = email.Header.decode_header(email_msg["From"])
|
||||||
@@ -228,48 +229,48 @@ class MailConnection(object):
|
|||||||
email_from = u""
|
email_from = u""
|
||||||
result = u"From : "
|
result = u"From : "
|
||||||
for i in range(len(from_decoded)):
|
for i in range(len(from_decoded)):
|
||||||
if from_decoded[i][1]:
|
try:
|
||||||
charset_hint = from_decoded[i][1]
|
if from_decoded[i][1]:
|
||||||
email_from += unicode(from_decoded[i][0].decode(from_decoded[i][1]))
|
charset_hint = from_decoded[i][1]
|
||||||
else:
|
email_from += unicode(from_decoded[i][0].decode(from_decoded[i][1]))
|
||||||
try:
|
else:
|
||||||
email_from += unicode(from_decoded[i][0])
|
email_from += unicode(from_decoded[i][0])
|
||||||
except Exception,e:
|
except Exception,e:
|
||||||
|
try:
|
||||||
|
email_from += unicode(from_decoded[i][0].decode("iso-8859-1"))
|
||||||
|
except Exception, e:
|
||||||
try:
|
try:
|
||||||
email_from += unicode(from_decoded[i][0].decode("iso-8859-1"))
|
email_from += unicode(from_decoded[i][0].decode(default_encoding))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
try:
|
type, value, stack = sys.exc_info()
|
||||||
email_from += unicode(from_decoded[i][0].decode(default_encoding))
|
print >>sys.stderr, "".join(traceback.format_exception
|
||||||
except Exception, e:
|
(type, value, stack, 5))
|
||||||
type, value, stack = sys.exc_info()
|
|
||||||
print >>sys.stderr, "".join(traceback.format_exception
|
|
||||||
(type, value, stack, 5))
|
|
||||||
result += email_from + u"\n"
|
result += email_from + u"\n"
|
||||||
|
|
||||||
subject_decoded = email.Header.decode_header(email_msg["Subject"])
|
subject_decoded = email.Header.decode_header(email_msg["Subject"])
|
||||||
result += u"Subject : "
|
result += u"Subject : "
|
||||||
for i in range(len(subject_decoded)):
|
for i in range(len(subject_decoded)):
|
||||||
if subject_decoded[i][1]:
|
try:
|
||||||
charset_hint = subject_decoded[i][1]
|
if subject_decoded[i][1]:
|
||||||
result += unicode(subject_decoded[i][0].decode(subject_decoded[i][1]))
|
charset_hint = subject_decoded[i][1]
|
||||||
else:
|
result += unicode(subject_decoded[i][0].decode(subject_decoded[i][1]))
|
||||||
try:
|
else:
|
||||||
result += unicode(subject_decoded[i][0])
|
result += unicode(subject_decoded[i][0])
|
||||||
except Exception,e:
|
except Exception,e:
|
||||||
|
try:
|
||||||
|
result += unicode(subject_decoded[i][0].decode("iso-8859-1"))
|
||||||
|
except Exception, e:
|
||||||
try:
|
try:
|
||||||
result += unicode(subject_decoded[i][0].decode("iso-8859-1"))
|
result += unicode(subject_decoded[i][0].decode(default_encoding))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
try:
|
if charset_hint is not None:
|
||||||
result += unicode(subject_decoded[i][0].decode(default_encoding))
|
try:
|
||||||
except Exception, e:
|
result += unicode(subject_decoded[i][0].decode(charset_hint))
|
||||||
if charset_hint is not None:
|
except Exception, e:
|
||||||
try:
|
type, value, stack = sys.exc_info()
|
||||||
result += unicode(subject_decoded[i][0].decode(charset_hint))
|
print >>sys.stderr, "".join(traceback.format_exception
|
||||||
except Exception, e:
|
(type, value, stack, 5))
|
||||||
type, value, stack = sys.exc_info()
|
|
||||||
print >>sys.stderr, "".join(traceback.format_exception
|
|
||||||
(type, value, stack, 5))
|
|
||||||
|
|
||||||
result += u"\n\n"
|
result += u"\n\n"
|
||||||
|
|
||||||
if include_body:
|
if include_body:
|
||||||
|
|||||||
Reference in New Issue
Block a user