You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/11/04 16:52:36 UTC

[1/3] git commit: [#6328] ticket:465 Fix tests failing due to new sendmail argument

Updated Branches:
  refs/heads/master 573d35eec -> 7c84b6b14


[#6328] ticket:465 Fix tests failing due to new sendmail argument


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

Branch: refs/heads/master
Commit: 59e482695a62c0a59a1993b8cd94745f069cbbe0
Parents: 374ae60
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri Nov 1 09:03:44 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Nov 4 15:45:50 2013 +0000

----------------------------------------------------------------------
 Allura/allura/tests/model/test_notification.py | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/59e48269/Allura/allura/tests/model/test_notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_notification.py b/Allura/allura/tests/model/test_notification.py
index cf854b4..78993ae 100644
--- a/Allura/allura/tests/model/test_notification.py
+++ b/Allura/allura/tests/model/test_notification.py
@@ -79,6 +79,7 @@ class TestNotification(unittest.TestCase):
                 from_address='from_address',
                 reply_to_address='reply_to_address',
                 in_reply_to='in_reply_to',
+                references=['a'],
                 subject='subject',
                 text='text',
             )
@@ -91,6 +92,7 @@ class TestNotification(unittest.TestCase):
                 subject='subject',
                 message_id='_id',
                 in_reply_to='in_reply_to',
+                references=['a'],
                 sender='wiki@test.p.in.sf.net',
                 text='text footer',
             )
@@ -139,6 +141,7 @@ class TestNotification(unittest.TestCase):
                 from_address='from_address',
                 reply_to_address='reply_to_address',
                 in_reply_to='in_reply_to',
+                references=['a'],
                 subject='subject',
                 text='text',
             )
@@ -152,6 +155,7 @@ class TestNotification(unittest.TestCase):
                 subject='subject',
                 message_id='_id',
                 in_reply_to='in_reply_to',
+                references=['a'],
                 sender='wiki@test.p.in.sf.net',
                 text='text footer',
             )


[2/3] git commit: [#6328] ticket:465 Add all parent ids to References:

Posted by jo...@apache.org.
[#6328] ticket:465 Add all parent ids to References:


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

Branch: refs/heads/master
Commit: 374ae606071625aad1b981b9fdd86e76fa699fdb
Parents: 573d35e
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Oct 31 15:17:43 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Nov 4 15:45:50 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/mail_util.py                        | 12 ++++++++++--
 Allura/allura/model/notification.py                   | 14 ++++++++++++++
 Allura/allura/tasks/mail_tasks.py                     | 13 +++++++------
 .../forgetracker/tests/functional/test_root.py        |  3 +++
 4 files changed, 34 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/374ae606/Allura/allura/lib/mail_util.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index ca156a9..9bb5759 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -182,7 +182,8 @@ class SMTPClient(object):
     def __init__(self):
         self._client = None
 
-    def sendmail(self, addrs, fromaddr, reply_to, subject, message_id, in_reply_to, message, sender=None):
+    def sendmail(self, addrs, fromaddr, reply_to, subject, message_id, in_reply_to, message,
+                 sender=None, references=None):
         if not addrs: return
         # We send one message with multiple envelope recipients, so use a generic To: addr
         # It might be nice to refactor to send one message per recipient, and use the actual To: addr
@@ -197,7 +198,14 @@ class SMTPClient(object):
             if not isinstance(in_reply_to, basestring):
                 raise TypeError('Only strings are supported now, not lists')
             message['In-Reply-To'] = Header(u'<%s>' % in_reply_to)
-            message['References'] = message['In-Reply-To']
+            if not references:
+                message['References'] = message['In-Reply-To']
+        if references:
+            if isinstance(references, list):
+                references = [u'<%s>' % r for r in references]
+            else:
+                references = [references]
+            message['References'] = Header(*references)
         content = message.as_string()
         smtp_addrs = map(_parse_smtp_addr, addrs)
         smtp_addrs = [ a for a in smtp_addrs if isvalid(a) ]

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/374ae606/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index e4db041..5da7fd3 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -83,6 +83,7 @@ class Notification(MappedClass):
 
     # Notification Content
     in_reply_to=FieldProperty(str)
+    references=FieldProperty([str])
     from_address=FieldProperty(str)
     reply_to_address=FieldProperty(str)
     subject=FieldProperty(str)
@@ -170,6 +171,7 @@ class Notification(MappedClass):
                 subject=subject_prefix + subject,
                 text=text,
                 in_reply_to=parent_msg_id,
+                references=cls._references(artifact, post),
                 author_id=author._id,
                 pubdate=datetime.utcnow())
         elif topic == 'flash':
@@ -237,6 +239,16 @@ class Notification(MappedClass):
         app = app_config.project.app_instance(app_config)
         return app.email_address if app else None
 
+    @classmethod
+    def _references(cls, artifact, post):
+        msg_ids = []
+        while post.parent_id:
+            msg_ids.append(artifact.url() + post.parent_id)
+            post = post.parent
+        msg_ids.append(artifact.message_id())
+        msg_ids.reverse()
+        return msg_ids
+
     def send_simple(self, toaddr):
         allura.tasks.mail_tasks.sendsimplemail.post(
             toaddr=toaddr,
@@ -246,6 +258,7 @@ class Notification(MappedClass):
             sender=self._sender(),
             message_id=self._id,
             in_reply_to=self.in_reply_to,
+            references=self.references,
             text=(self.text or '') + self.footer(toaddr))
 
     def send_direct(self, user_id):
@@ -273,6 +286,7 @@ class Notification(MappedClass):
             subject=self.subject,
             message_id=self._id,
             in_reply_to=self.in_reply_to,
+            references=self.references,
             sender=self._sender(),
             text=(self.text or '') + self.footer())
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/374ae606/Allura/allura/tasks/mail_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index 0d7fc6d..0af9a42 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -76,7 +76,7 @@ def route_email(
 
 @task
 def sendmail(fromaddr, destinations, text, reply_to, subject,
-             message_id, in_reply_to=None, sender=None):
+             message_id, in_reply_to=None, sender=None, references=None):
     from allura import model as M
     addrs_plain = []
     addrs_html = []
@@ -126,13 +126,13 @@ def sendmail(fromaddr, destinations, text, reply_to, subject,
     multi_msg = mail_util.make_multipart_message(plain_msg, html_msg)
     smtp_client.sendmail(
         addrs_multi, fromaddr, reply_to, subject, message_id,
-        in_reply_to, multi_msg, sender=sender)
+        in_reply_to, multi_msg, sender=sender, references=references)
     smtp_client.sendmail(
         addrs_plain, fromaddr, reply_to, subject, message_id,
-        in_reply_to, plain_msg, sender=sender)
+        in_reply_to, plain_msg, sender=sender, references=references)
     smtp_client.sendmail(
         addrs_html, fromaddr, reply_to, subject, message_id,
-        in_reply_to, html_msg, sender=sender)
+        in_reply_to, html_msg, sender=sender, references=references)
 
 @task
 def sendsimplemail(
@@ -143,7 +143,8 @@ def sendsimplemail(
     subject,
     message_id,
     in_reply_to=None,
-    sender=None):
+    sender=None,
+    references=None):
     from allura import model as M
     if fromaddr is None:
         fromaddr = u'noreply@in.sf.net'
@@ -162,4 +163,4 @@ def sendsimplemail(
     multi_msg = mail_util.make_multipart_message(plain_msg, html_msg)
     smtp_client.sendmail(
         [toaddr], fromaddr, reply_to, subject, message_id,
-        in_reply_to, multi_msg, sender=sender)
+        in_reply_to, multi_msg, sender=sender, references=None)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/374ae606/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index b710b60..be2a0b2 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -2758,6 +2758,7 @@ class TestNotificationEmailGrouping(TrackerTestController):
         ticket = tm.Ticket.query.get(ticket_num=1)
         assert_equal(email.kwargs.message_id, ticket.message_id())
         assert_equal(email.kwargs.in_reply_to, None)
+        assert_equal(email.kwargs.references, [])
 
     def test_comments(self):
         def find(d, pred):
@@ -2783,6 +2784,7 @@ class TestNotificationEmailGrouping(TrackerTestController):
         top_level_comment_msg_id = ticket.url() + top_level_comment._id
         assert_equal(email.kwargs.message_id, top_level_comment_msg_id)
         assert_equal(email.kwargs.in_reply_to, ticket.message_id())
+        assert_equal(email.kwargs.references, [ticket.message_id()])
 
         ThreadLocalORMSession.flush_all()
         M.MonQTask.query.remove()
@@ -2802,3 +2804,4 @@ class TestNotificationEmailGrouping(TrackerTestController):
         reply = [post for post in ticket.discussion_thread.posts if post.text == reply_text][0]
         assert_equal(email.kwargs.message_id, ticket.url() + reply._id)
         assert_equal(email.kwargs.in_reply_to, top_level_comment_msg_id)
+        assert_equal(email.kwargs.references, [ticket.message_id(), top_level_comment_msg_id])


[3/3] git commit: [#6328] ticket:465 Fix references header and test

Posted by jo...@apache.org.
[#6328] ticket:465 Fix references header and test


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

Branch: refs/heads/master
Commit: 7c84b6b14b8c18a6cdc2b4d67523b10870d74f2f
Parents: 59e4826
Author: Igor Bondarenko <je...@gmail.com>
Authored: Mon Nov 4 09:14:52 2013 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Mon Nov 4 15:45:51 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/mail_util.py    |  7 ++-----
 Allura/allura/tasks/mail_tasks.py |  2 +-
 Allura/allura/tests/test_tasks.py | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7c84b6b1/Allura/allura/lib/mail_util.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index 9bb5759..6eb6bf0 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -24,7 +24,7 @@ from email.MIMEText import MIMEText
 from email import header
 
 import tg
-from paste.deploy.converters import asbool, asint
+from paste.deploy.converters import asbool, asint, aslist
 from formencode import validators as fev
 from pylons import tmpl_context as c
 
@@ -201,10 +201,7 @@ class SMTPClient(object):
             if not references:
                 message['References'] = message['In-Reply-To']
         if references:
-            if isinstance(references, list):
-                references = [u'<%s>' % r for r in references]
-            else:
-                references = [references]
+            references = [u'<%s>' % r for r in aslist(references)]
             message['References'] = Header(*references)
         content = message.as_string()
         smtp_addrs = map(_parse_smtp_addr, addrs)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7c84b6b1/Allura/allura/tasks/mail_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index 0af9a42..a33c560 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -163,4 +163,4 @@ def sendsimplemail(
     multi_msg = mail_util.make_multipart_message(plain_msg, html_msg)
     smtp_client.sendmail(
         [toaddr], fromaddr, reply_to, subject, message_id,
-        in_reply_to, multi_msg, sender=sender, references=None)
+        in_reply_to, multi_msg, sender=sender, references=references)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7c84b6b1/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index e5a2ecd..0cf5e60 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -310,6 +310,38 @@ class TestMailTasks(unittest.TestCase):
             assert_in('From: "Test Admin" <te...@users.localhost>', body)
             assert_in('Sender: tickets@test.p.sf.net', body)
 
+    def test_email_references_header(self):
+        c.user = M.User.by_username('test-admin')
+        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
+            mail_tasks.sendsimplemail(
+                fromaddr=str(c.user._id),
+                toaddr='test@mail.com',
+                text=u'This is a test',
+                reply_to=u'noreply@sf.net',
+                subject=u'Test subject',
+                references=['a', 'b', 'c'],
+                message_id=h.gen_message_id())
+            assert_equal(_client.sendmail.call_count, 1)
+            return_path, rcpts, body = _client.sendmail.call_args[0]
+            body = body.split('\n')
+            assert_in('From: "Test Admin" <te...@users.localhost>', body)
+            assert_in('References: <a> <b> <c>', body)
+
+            _client.reset_mock()
+            mail_tasks.sendmail(
+                fromaddr=str(c.user._id),
+                destinations=[ str(c.user._id) ],
+                text=u'This is a test',
+                reply_to=u'noreply@sf.net',
+                subject=u'Test subject',
+                references=u'ref',
+                message_id=h.gen_message_id())
+            assert_equal(_client.sendmail.call_count, 1)
+            return_path, rcpts, body = _client.sendmail.call_args[0]
+            body = body.split('\n')
+            assert_in('From: "Test Admin" <te...@users.localhost>', body)
+            assert_in('References: <ref>', body)
+
     @td.with_wiki
     def test_receive_email_ok(self):
         c.user = M.User.by_username('test-admin')