Skip to content
Browse files

Applied fix in 6c7d264 to MessageLog

  • Loading branch information...
1 parent 3d8548d commit a2f67c411cfcc79a4caa80a56383b787bcfe3d74 @spookylukey committed Jun 24, 2010
Showing with 24 additions and 19 deletions.
  1. +24 −19 mailer/models.py
View
43 mailer/models.py
@@ -61,6 +61,26 @@ def retry_deferred(self, new_priority=2):
return count
+def email_to_db(email):
+ # pickle.dumps returns essentially binary data which we need to encode
+ # to store in a unicode field.
+ return base64.encodestring(pickle.dumps(email))
+
+
+def db_to_email(data):
+ if data == u"":
+ return None
+ else:
+ try:
+ return pickle.loads(base64.decodestring(data))
+ except Exception:
+ try:
+ # previous method was to just do pickle.dumps(val)
+ return pickle.loads(data.encode("ascii"))
+ except Exception:
+ return None
+
+
class Message(models.Model):
# The actual data - a pickled EmailMessage
@@ -85,23 +105,11 @@ def retry(self, new_priority=2):
return False
def _get_email(self):
- if self.message_data == u"":
- return None
- else:
- try:
- return pickle.loads(base64.decodestring(self.message_data))
- except Exception:
- try:
- # previous method was to just do pickle.dumps(val)
- return pickle.loads(self.message_data.encode("ascii"))
- except Exception:
- return None
+ return db_to_email(self.message_data)
def _set_email(self, val):
- # pickle.dumps returns essentially binary data which we need to encode
- # to store in a unicode field.
- self.message_data = base64.encodestring(pickle.dumps(val))
-
+ self.message_data = email_to_db(val)
+
email = property(_get_email, _set_email, doc=
"""EmailMessage object. If this is mutated, you will need to
set the attribute again to cause the underlying serialised data to be updated.""")
@@ -230,10 +238,7 @@ class MessageLog(models.Model):
@property
def email(self):
- if self.message_data == "":
- return None
- else:
- return pickle.loads(self.message_data.encode("ascii"))
+ return db_to_email(self.message_data)
@property
def to_addresses(self):

0 comments on commit a2f67c4

Please sign in to comment.
Something went wrong with that request. Please try again.