Skip to content

Commit 25e097f

Browse files
author
Richard Jones
committed
more complete fix for email charset
1 parent 6fb090c commit 25e097f

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Fixed:
99
user-friendly (sf bug 904064)
1010
- don't add a query to a user's list if it's already there
1111
- nicer invalid property error in HTML templating
12+
- use EMAIL_CHARSET for message body too (still sf bug 900046)
1213

1314

1415
2004-02-25 0.6.6

roundup/roundupdb.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: roundupdb.py,v 1.86.2.2 2004-02-23 05:37:11 richard Exp $
18+
# $Id: roundupdb.py,v 1.86.2.3 2004-02-28 22:53:16 richard Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
@@ -209,9 +209,15 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
209209
self.classname, nodeid, self.db.config.MAIL_DOMAIN)
210210
messages.set(msgid, messageid=messageid)
211211

212-
# send an email to the people who missed out
212+
# character set to encode the email with
213+
charset = getattr(self.db.config, 'EMAIL_CHARSET', 'utf-8')
214+
215+
# title for the message
213216
cn = self.classname
214217
title = self.get(nodeid, 'title') or '%s message copy'%cn
218+
if charset != 'utf-8':
219+
title = unicode(title, 'utf-8').encode(charset)
220+
215221
# figure author information
216222
authid = messages.get(msgid, 'author')
217223
authname = users.get(authid, 'realname')
@@ -249,7 +255,10 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
249255
m.append(self.email_signature(nodeid, msgid))
250256

251257
# encode the content as quoted-printable
252-
content = cStringIO.StringIO('\n'.join(m))
258+
m = '\n'.join(m)
259+
if charset != 'utf-8':
260+
m = unicode(m, 'utf-8').encode(charset)
261+
content = cStringIO.StringIO(m)
253262
content_encoded = cStringIO.StringIO()
254263
quopri.encode(content, content_encoded, 0)
255264
content_encoded = content_encoded.getvalue()
@@ -273,12 +282,11 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
273282
message = cStringIO.StringIO()
274283
writer = MimeWriter.MimeWriter(message)
275284
writer.addheader('Subject', '[%s%s] %s'%(cn, nodeid,
276-
encode_header(title, self.db.config.EMAIL_CHARSET)))
285+
encode_header(title, charset)))
277286
writer.addheader('To', ', '.join(sendto))
278-
writer.addheader('From', straddr((encode_header(authname,
279-
self.db.config.EMAIL_CHARSET) + from_tag, from_address)))
280-
tracker_name = encode_header(self.db.config.TRACKER_NAME,
281-
self.db.config.EMAIL_CHARSET)
287+
writer.addheader('From', straddr((encode_header(authname, charset)
288+
+ from_tag, from_address)))
289+
tracker_name = encode_header(self.db.config.TRACKER_NAME, charset)
282290
writer.addheader('Reply-To', straddr((tracker_name, from_address)))
283291
writer.addheader('Date', time.strftime("%a, %d %b %Y %H:%M:%S +0000",
284292
time.gmtime()))
@@ -299,7 +307,7 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
299307
part = writer.startmultipartbody('mixed')
300308
part = writer.nextpart()
301309
part.addheader('Content-Transfer-Encoding', 'quoted-printable')
302-
body = part.startbody('text/plain; charset=utf-8')
310+
body = part.startbody('text/plain; charset=%s'%charset)
303311
body.write(content_encoded)
304312
for fileid in message_files:
305313
name = files.get(fileid, 'name')
@@ -327,7 +335,7 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
327335
writer.lastpart()
328336
else:
329337
writer.addheader('Content-Transfer-Encoding', 'quoted-printable')
330-
body = writer.startbody('text/plain; charset=utf-8')
338+
body = writer.startbody('text/plain; charset=%s'%charset)
331339
body.write(content_encoded)
332340

333341
# now try to send the message

0 commit comments

Comments
 (0)