Skip to content

Commit e96789a

Browse files
committed
mailer string encoding fixes
1 parent 5cb03a4 commit e96789a

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

roundup/mailer.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from email.mime.multipart import MIMEMultipart
1616

1717
from roundup.anypy import email_
18-
from roundup.anypy.strings import b2s, s2u
18+
from roundup.anypy.strings import b2s, s2b, s2u
1919

2020
try:
2121
import pyme, pyme.core
@@ -27,9 +27,9 @@ class MessageSendError(RuntimeError):
2727
pass
2828

2929
def encode_quopri(msg):
30-
orig = msg.get_payload()
30+
orig = s2b(msg.get_payload())
3131
encdata = quopri.encodestring(orig)
32-
msg.set_payload(encdata)
32+
msg.set_payload(b2s(encdata))
3333
del msg['Content-Transfer-Encoding']
3434
msg['Content-Transfer-Encoding'] = 'quoted-printable'
3535

@@ -92,7 +92,8 @@ def set_message_attributes(self, message, to, subject, author=None):
9292
name = s2u(author[0])
9393
author = nice_sender_header(name, author[1], charset)
9494
try:
95-
message['Subject'] = subject.encode('ascii')
95+
subject.encode('ascii')
96+
message['Subject'] = subject
9697
except UnicodeError:
9798
message['Subject'] = Header(subject, charset)
9899
message['To'] = ', '.join(to)
@@ -104,7 +105,8 @@ def set_message_attributes(self, message, to, subject, author=None):
104105

105106
# Add a unique Roundup header to help filtering
106107
try:
107-
message['X-Roundup-Name'] = tracker_name.encode('ascii')
108+
tracker_name.encode('ascii')
109+
message['X-Roundup-Name'] = tracker_name
108110
except UnicodeError:
109111
message['X-Roundup-Name'] = Header(tracker_name, charset)
110112

roundup/roundupdb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,9 @@ def send_message(self, issueid, msgid, note, sendto, from_address=None,
496496
charset = getattr(self.db.config, 'EMAIL_CHARSET', 'utf-8')
497497

498498
# construct the content and convert to unicode object
499-
body = s2u('\n'.join(m)).encode(charset)
499+
body = s2u('\n'.join(m))
500+
if type(body) != type(''):
501+
body = body.encode(charset)
500502

501503
# make sure the To line is always the same (for testing mostly)
502504
sendto.sort()
@@ -588,7 +590,8 @@ def send_message(self, issueid, msgid, note, sendto, from_address=None,
588590
values = ', '.join(values)
589591
header = "X-Roundup-%s-%s"%(self.classname, propname)
590592
try:
591-
message[header] = values.encode('ascii')
593+
values.encode('ascii')
594+
message[header] = values
592595
except UnicodeError:
593596
message[header] = Header(values, charset)
594597

0 commit comments

Comments
 (0)