allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#8160] Fixes unicode acceptance in handle_artifact_message
Date Thu, 28 Sep 2017 19:37:12 GMT
Repository: allura
Updated Branches:
  refs/heads/master 96b4ebf44 -> 3395a18a6


[#8160] Fixes unicode acceptance in handle_artifact_message


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/3395a18a
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/3395a18a
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/3395a18a

Branch: refs/heads/master
Commit: 3395a18a67943a7f7aff0c5803cc361274083d06
Parents: 96b4ebf
Author: Kenton Taylor <ktaylor@slashdotmedia.com>
Authored: Thu Sep 28 09:13:16 2017 -0400
Committer: Dave Brondsema <dave@brondsema.net>
Committed: Thu Sep 28 15:33:05 2017 -0400

----------------------------------------------------------------------
 Allura/allura/app.py            |  7 ++++-
 Allura/allura/tests/test_app.py | 54 ++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/3395a18a/Allura/allura/app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/app.py b/Allura/allura/app.py
index 6c97169..937702e 100644
--- a/Allura/allura/app.py
+++ b/Allura/allura/app.py
@@ -709,7 +709,12 @@ class Application(object):
             log.info(
                 'Existing message_id %s found - saving this as text attachment' %
                 message_id)
-            fp = StringIO(message['payload'])
+
+            try:
+                fp = StringIO(message['payload'].encode('utf-8'))
+            except UnicodeDecodeError:
+                fp = StringIO(message['payload'])
+
             post.attach(
                 'alternate', fp,
                 content_type=message.get(

http://git-wip-us.apache.org/repos/asf/allura/blob/3395a18a/Allura/allura/tests/test_app.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_app.py b/Allura/allura/tests/test_app.py
index 0e20905..926a71b 100644
--- a/Allura/allura/tests/test_app.py
+++ b/Allura/allura/tests/test_app.py
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
 #       Licensed to the Apache Software Foundation (ASF) under one
 #       or more contributor license agreements.  See the NOTICE file
 #       distributed with this work for additional information
@@ -24,6 +26,7 @@ from formencode import validators as fev
 from alluratest.controller import setup_unit_test
 from allura import app
 from allura.lib.app_globals import Icon
+from allura.lib import mail_util
 
 
 def setUp():
@@ -121,3 +124,54 @@ def test_sitemap():
     sm.extend([app.SitemapEntry('a', 'a/')[
         app.SitemapEntry('d', 'd/')]])
     assert len(sm.children) == 3
+
+
+@mock.patch('allura.app.Application.PostClass.query.get')
+def test_handle_artifact_unicode(qg):
+    """
+    Tests that app.handle_artifact_message can accept utf strings
+    """
+    ticket = mock.MagicMock()
+    ticket.get_discussion_thread.return_value = (mock.MagicMock(), mock.MagicMock())
+    post = mock.MagicMock()
+    qg.return_value = post
+
+    a = app.Application(c.project, c.app.config)
+
+    msg = dict(payload=u'foo ƒ†©¥˙¨ˆ', message_id=1, headers={})
+    a.handle_artifact_message(ticket, msg)
+    assert_equal(post.attach.call_args[0][1].getvalue(), 'foo ƒ†©¥˙¨ˆ')
+
+    msg = dict(payload='foo', message_id=1, headers={})
+    a.handle_artifact_message(ticket, msg)
+    assert_equal(post.attach.call_args[0][1].getvalue(), 'foo')
+
+    msg = dict(payload="\x94my quote\x94", message_id=1, headers={})
+    a.handle_artifact_message(ticket, msg)
+    assert_equal(post.attach.call_args[0][1].getvalue(), '\x94my quote\x94')
+
+    # assert against prod example
+    msg_raw = """Message-Id: <1502352031.3216858.1068961568.19EF48C6@webmail.messagingengine.com>
+From: foo <foo@bar.com>
+To: "[forge:site-support]" <15391@site-support.forge.p.re.sf.net>
+MIME-Version: 1.0
+Content-Transfer-Encoding: 7bit
+Content-Type: multipart/alternative; boundary="_----------=_150235203132168580"
+Date: Thu, 10 Aug 2017 10:00:31 +0200
+Subject: Re: [forge:site-support] #15391 Unable to join (my own) mailing list
+This is a multi-part message in MIME format.
+--_----------=_150235203132168580
+Content-Transfer-Encoding: quoted-printable
+Content-Type: text/plain; charset="utf-8"
+Hi
+--_----------=_150235203132168580
+Content-Transfer-Encoding: quoted-printable
+Content-Type: text/html; charset="utf-8"
+<!DOCTYPE html>
+<html><body>Hi</body></html>
+--_----------=_150235203132168580--
+    """
+    msg = mail_util.parse_message(msg_raw)
+    for p in filter(lambda p: p['payload'] != None, msg['parts']):
+        # filter here mimics logic in `route_email`
+        a.handle_artifact_message(ticket, p)


Mime
View raw message