X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fmodels.py;h=1da1d998bece9d0b2d5046ca0a74666cbaf16318;hb=94ae2713d4aca80b7dc1168a60f98bbe38d86e12;hp=3cfbacdacdd7dd75065dba2125ab9c24d55a3019;hpb=e0fac2b893fd69caedd00c9256ac1e59c8dcbc9b;p=patchwork diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 3cfbacd..1da1d99 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -31,11 +31,13 @@ import string import random try: - from email.mime.text import MIMEText + from email.mime.nonmultipart import MIMENonMultipart + from email.encoders import encode_7or8bit import email.utils except ImportError: # Python 2.4 compatibility - from email.MIMEText import MIMEText + from email.MIMENonMultipart import MIMENonMultipart + from email.Encoders import encode_7or8bit import email.Utils email.utils = email.Utils @@ -167,6 +169,14 @@ class HashField(models.CharField): def db_type(self): return 'char(%d)' % self.n_bytes +class PatchMbox(MIMENonMultipart): + patch_charset = 'utf-8' + def __init__(self, _text): + MIMENonMultipart.__init__(self, 'text', 'plain', + **{'charset': self.patch_charset}) + self.set_payload(_text.encode(self.patch_charset)) + encode_7or8bit(self) + class Patch(models.Model): project = models.ForeignKey(Project) msgid = models.CharField(max_length=255, unique = True) @@ -238,11 +248,11 @@ class Patch(models.Model): body += self.content - mail = MIMEText(body, _charset = 'utf-8') + mail = PatchMbox(body) mail['Subject'] = self.name mail['Date'] = email.utils.formatdate( time.mktime(self.date.utctimetuple())) - mail['From'] = str(self.submitter) + mail['From'] = unicode(self.submitter) mail['X-Patchwork-Id'] = str(self.id) mail.set_unixfrom('From patchwork ' + self.date.ctime())