Permalink
Browse files

Fixed MailHandler with unicode messages for Python 2.4 and 2.5

  • Loading branch information...
1 parent 2ca8ee8 commit a9805aebf0eae9a8c6fa778738b712a83fdc2b80 @dvarrazzo dvarrazzo committed Dec 5, 2012
Showing with 6 additions and 0 deletions.
  1. +6 −0 logbook/handlers.py
View
6 logbook/handlers.py
@@ -1111,6 +1111,12 @@ def message_from_record(self, record, suppressed):
if suppressed:
body += '\r\n\r\nThis message occurred additional %d ' \
'time(s) and was suppressed' % suppressed
+
+ # inconsistency in Python 2.4 and 2.5
+ # other versions correctly return msg.get_payload() as str
+ if sys.version_info < (2, 6) and isinstance(body, unicode):
+ body = body.encode('utf-8')
+
msg.set_payload(body, 'UTF-8')
return msg

0 comments on commit a9805ae

Please sign in to comment.