You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/05/30 18:24:13 UTC

[allura] branch db/8289 created (now 4a0df37)

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a change to branch db/8289
in repository https://gitbox.apache.org/repos/asf/allura.git.


      at 4a0df37  [#8289] don't error if no request ip

This branch includes the following new commits:

     new 553a3f7  [#8289] fix inbound mail encoding issue
     new 4a0df37  [#8289] don't error if no request ip

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[allura] 01/02: [#8289] fix inbound mail encoding issue

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8289
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 553a3f7130f2ff0151dafae07133545add8d265c
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Thu May 30 13:50:48 2019 -0400

    [#8289] fix inbound mail encoding issue
---
 Allura/allura/lib/mail_util.py        |  5 +++-
 Allura/allura/tasks/mail_tasks.py     |  2 +-
 Allura/allura/tests/test_mail_util.py | 54 ++++++++++++++++++++++++++++++++++-
 3 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index ea906bf..7fbace5 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -23,6 +23,7 @@ from email.MIMEMultipart import MIMEMultipart
 from email.MIMEText import MIMEText
 from email import header
 
+import six
 import tg
 from paste.deploy.converters import asbool, asint, aslist
 from formencode import validators as fev
@@ -155,8 +156,10 @@ def parse_message(data):
     else:
         result['payload'] = msg.get_payload(decode=True)
         charset = msg.get_content_charset()
-        if charset:
+        # payload is sometimes already unicode (due to being saved in mongo?)
+        if isinstance(result['payload'], six.binary_type) and charset:
             result['payload'] = result['payload'].decode(charset)
+
     return result
 
 
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index d60533f..43a9f1a 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -62,7 +62,7 @@ def route_email(
     '''
     try:
         msg = mail_util.parse_message(data)
-    except:  # pragma no cover
+    except Exception:  # pragma no cover
         log.exception('Parse Error: (%r,%r,%r)', peer, mailfrom, rcpttos)
         return
     if mail_util.is_autoreply(msg):
diff --git a/Allura/allura/tests/test_mail_util.py b/Allura/allura/tests/test_mail_util.py
index 13b5b42..4f99840 100644
--- a/Allura/allura/tests/test_mail_util.py
+++ b/Allura/allura/tests/test_mail_util.py
@@ -22,7 +22,7 @@ from email.MIMEMultipart import MIMEMultipart
 from email.MIMEText import MIMEText
 
 import mock
-from nose.tools import raises, assert_equal, assert_false, assert_true
+from nose.tools import raises, assert_equal, assert_false, assert_true, assert_in
 from ming.orm import ThreadLocalORMSession
 from tg import config as tg_config
 
@@ -96,6 +96,58 @@ class TestReactor(unittest.TestCase):
         s_msg = msg1.as_string()
         msg2 = parse_message(s_msg)
         assert isinstance(msg2['payload'], unicode)
+        assert_in(u'всех', msg2['payload'])
+
+    def test_more_encodings(self):
+        # these are unicode strings to reflect behavior after loading 'route_email' tasks from mongo
+        s_msg = u"""Date: Sat, 25 May 2019 09:32:00 +1000
+From: <fo...@bar.com>
+To: <38...@bugs.proj.localhost>
+Subject: bugs
+Content-Type: text/plain; charset=GBK
+Content-Transfer-Encoding: base64
+
+VGhlIFNuYXA3IGFwcGxpY2F0aW9uKGJhc2VkIG9uIHNuYXA3LWZ1bGwtMS40LjIpIGhhcyBiZWVu
+IHJ1biBvdmVyIGEgd2VlayBvbiBRTlg2LjYuMCwKQnV0IHNvbWV0aW1lcyAsc3lzdGVtIHNjcmVl
+biB3aWxsIHByaW50CiJsZGQ6RkFUQUw6Y291bGQgbm90IGxvYWQgbGlicmFyeSBsaWJzb2NrZXQu
+c28uMyIsClRoZSBhcHBsaWNhdGlvbidzIGNvbW11bmljYXRpb24gd29yayB3ZWxsICxidXQgdGhl
+IGZ0cCx0ZWxuZXQscGluZyBjYW4ndCB3b3JrICEKCgpXaHk/
+"""
+        msg = parse_message(s_msg)
+        assert isinstance(msg['payload'], unicode)
+        assert_in(u'The Snap7 application', msg['payload'])
+
+        s_msg = u"""Date: Sat, 25 May 2019 09:32:00 +1000
+From: <fo...@bar.com>
+To: <38...@bugs.proj.localhost>
+Subject: bugs
+Content-Type: text/plain; charset=utf-8
+Content-Disposition: inline
+Content-Transfer-Encoding: 8bit
+
+> Status: closed
+> Created: Thu May 23, 2019 09:24 PM UTC by admin1
+> Attachments:
+> 
+>   • foo.txt (1.0 kB; text/plain)
+> 
+"""
+        msg = parse_message(s_msg)
+        assert isinstance(msg['payload'], unicode)
+        assert_in(u'• foo', msg['payload'])
+
+        s_msg = u"""Date: Sat, 25 May 2019 09:32:00 +1000
+From: <fo...@bar.com>
+To: <38...@bugs.proj.localhost>
+Subject: bugs
+Content-Type: TEXT/PLAIN; format=flowed; charset=ISO-8859-15
+Content-Transfer-Encoding: 8BIT
+
+programmed or èrogrammed ?
+"""
+        msg = parse_message(s_msg)
+        assert isinstance(msg['payload'], unicode)
+        assert_in(u'èrogrammed', msg['payload'])
 
     def test_unicode_complex_message(self):
         charset = 'utf-8'


[allura] 02/02: [#8289] don't error if no request ip

Posted by br...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8289
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 4a0df37c2a3893206d2454655970d35c70dc5260
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Thu May 30 14:05:57 2019 -0400

    [#8289] don't error if no request ip
---
 Allura/allura/lib/spam/stopforumspamfilter.py       | 9 ++++++---
 Allura/allura/tests/unit/spam/test_stopforumspam.py | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/Allura/allura/lib/spam/stopforumspamfilter.py b/Allura/allura/lib/spam/stopforumspamfilter.py
index 4e7a497..616d99f 100644
--- a/Allura/allura/lib/spam/stopforumspamfilter.py
+++ b/Allura/allura/lib/spam/stopforumspamfilter.py
@@ -57,7 +57,10 @@ class StopForumSpamSpamFilter(SpamFilter):
 
     def check(self, text, artifact=None, user=None, content_type='comment', **kw):
         ip = utils.ip_address(request)
-        ip_int = int(ipaddress.ip_address(unicode(ip)))
-        res = ip_int in self.packed_ips
-        self.record_result(res, artifact, user)
+        if ip:
+            ip_int = int(ipaddress.ip_address(unicode(ip)))
+            res = ip_int in self.packed_ips
+            self.record_result(res, artifact, user)
+        else:
+            res = False
         return res
diff --git a/Allura/allura/tests/unit/spam/test_stopforumspam.py b/Allura/allura/tests/unit/spam/test_stopforumspam.py
index 64963cf..77f0e89 100644
--- a/Allura/allura/tests/unit/spam/test_stopforumspam.py
+++ b/Allura/allura/tests/unit/spam/test_stopforumspam.py
@@ -49,3 +49,6 @@ class TestStopForumSpam(object):
 
         request.remote_addr = '1.1.1.1'
         assert_equal(False, self.sfs.check(self.content, artifact=self.artifact))
+
+        request.remote_addr = None  # e.g. from background task processing inbound email
+        assert_equal(False, self.sfs.check(self.content, artifact=self.artifact))