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 2016/08/16 15:53:11 UTC

[2/2] allura git commit: Added optional parameter metalink in sendmail function that adds a view button in email clients

Added optional parameter metalink in sendmail function that adds a view button in email clients


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

Branch: refs/heads/master
Commit: 9cd1c75b87f9abda5414e2b00ad7ba4fc6553686
Parents: 85f6765
Author: Rohan Verma <ro...@gmail.com>
Authored: Thu May 26 05:08:13 2016 +0530
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Tue Aug 16 11:52:38 2016 -0400

----------------------------------------------------------------------
 Allura/allura/model/notification.py |  1 +
 Allura/allura/tasks/mail_tasks.py   | 24 ++++++++++++++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/9cd1c75b/Allura/allura/model/notification.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/notification.py b/Allura/allura/model/notification.py
index a513795..955a75d 100644
--- a/Allura/allura/model/notification.py
+++ b/Allura/allura/model/notification.py
@@ -311,6 +311,7 @@ class Notification(MappedClass):
             in_reply_to=self.in_reply_to,
             references=self.references,
             sender=self._sender(),
+            metalink=h.absurl(self.link),
             text=(self.text or '') + self.footer())
 
     @classmethod

http://git-wip-us.apache.org/repos/asf/allura/blob/9cd1c75b/Allura/allura/tasks/mail_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index 2547291..963555f 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -30,11 +30,28 @@ log = logging.getLogger(__name__)
 
 smtp_client = mail_util.SMTPClient()
 
+def mail_meta_content(metalink):
+    '''
+    Helper function used to include a view action button in your email client
+    https://developers.google.com/gmail/markup/reference/go-to-action#view_action
+
+    :param metalink:  url to the page the action button links to
+    '''
+
+    return h.html.literal("""\
+    <div itemscope itemtype="http://schema.org/EmailMessage">
+    <div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
+      <link itemprop="url" href="%s"></link>
+      <meta itemprop="name" content="View"></meta>
+    </div>
+    <meta itemprop="description" content="View"></meta>
+    </div>""" % metalink)
 
 @task
 def route_email(
         peer, mailfrom, rcpttos, data):
-    '''Route messages according to their destination:
+    '''
+    Route messages according to their destination:
 
     <topic>@<mount_point>.<subproj2>.<subproj1>.<project>.projects.domain.net
     gets sent to c.app.handle_message(topic, message)
@@ -86,7 +103,7 @@ def route_email(
 
 @task
 def sendmail(fromaddr, destinations, text, reply_to, subject,
-             message_id, in_reply_to=None, sender=None, references=None):
+             message_id, in_reply_to=None, sender=None, references=None, metalink=None):
     '''
     Send an email to the specified list of destinations with respect to the preferred email format specified by user.
     It is best for broadcast messages.
@@ -141,6 +158,9 @@ def sendmail(fromaddr, destinations, text, reply_to, subject,
     htmlparser = HTMLParser.HTMLParser()
     plain_msg = mail_util.encode_email_part(htmlparser.unescape(text), 'plain')
     html_text = g.forge_markdown(email=True).convert(text)
+    if metalink != None:
+        html_text = html_text + mail_meta_content(metalink)
+
     html_msg = mail_util.encode_email_part(html_text, 'html')
     multi_msg = mail_util.make_multipart_message(plain_msg, html_msg)
     smtp_client.sendmail(