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:37 UTC

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

[#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])