Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/andialbrecht/buildbot
Browse files Browse the repository at this point in the history
* 'master' of git://github.com/andialbrecht/buildbot:
  Make LOG_ENCODING a module constant.
  Decode str before encoding when a log is added as mail attachment (fixes #2143).
  • Loading branch information
djmitche committed Nov 14, 2011
2 parents d14f92d + 43ebc29 commit 7497eff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion master/buildbot/status/mail.py
Expand Up @@ -49,6 +49,7 @@
VALID_EMAIL = re.compile("[a-zA-Z0-9\.\_\%\-\+]+@[a-zA-Z0-9\.\_\%\-]+.[a-zA-Z]{2,6}")

ENCODING = 'utf8'
LOG_ENCODING = 'utf-8'

class Domain(util.ComparableMixin):
implements(interfaces.IEmailLookup)
Expand Down Expand Up @@ -577,7 +578,10 @@ def createEmail(self, msgdict, builderName, title, results, builds=None,
log.getName())
if ( self._shouldAttachLog(log.getName()) or
self._shouldAttachLog(name) ):
a = MIMEText(log.getText().encode(ENCODING),
text = log.getText()
if not isinstance(text, unicode):
text = text.decode(LOG_ENCODING)
a = MIMEText(text.encode(ENCODING),
_charset=ENCODING)
a.add_header('Content-Disposition', "attachment",
filename=name)
Expand Down
4 changes: 3 additions & 1 deletion master/buildbot/test/unit/test_status_mail.py
Expand Up @@ -98,7 +98,9 @@ def test_createEmail_message_with_patch_and_log_containing_unicode(self):
builds = [ FakeBuildStatus(name="build") ]
msgdict = create_msgdict()
patches = [ ['', u'\u00E5\u00E4\u00F6', ''] ]
logs = [ FakeLog(u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).') ]
msg = u'Unicode log with non-ascii (\u00E5\u00E4\u00F6).'
# add msg twice: as unicode and already encoded
logs = [ FakeLog(msg), FakeLog(msg.encode('utf-8')) ]
mn = MailNotifier('from@example.org', addLogs=True)
m = mn.createEmail(msgdict, u'builder-n\u00E5me',
u'project-n\u00E5me', SUCCESS,
Expand Down

0 comments on commit 7497eff

Please sign in to comment.