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 2014/07/24 17:16:26 UTC

git commit: [#7579] Send mails with sendsimplemail to have correct To: header

Repository: allura
Updated Branches:
  refs/heads/master 0e18d9fc4 -> 2e1735cbc


[#7579] Send mails with sendsimplemail to have correct To: header


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

Branch: refs/heads/master
Commit: 2e1735cbc4f59b274d74eac0620f3e937c3b649b
Parents: 0e18d9f
Author: Alexander Luberg <al...@slashdotmedia.com>
Authored: Wed Jul 23 20:44:57 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Jul 24 15:15:59 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py           |  4 ++--
 Allura/allura/tasks/export_tasks.py         | 10 ++++++----
 Allura/allura/tasks/mail_tasks.py           | 19 +++++++++++++++++++
 Allura/allura/tests/functional/test_auth.py |  6 +++---
 Allura/allura/tests/test_tasks.py           |  2 +-
 Allura/docs/api/tasks.rst                   |  6 ++++++
 6 files changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/2e1735cb/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 4d15a9a..8835b33 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -196,8 +196,8 @@ class AuthController(BaseController):
                 hash=hash,
             ))
 
-            allura.tasks.mail_tasks.sendmail.post(
-                destinations=[email],
+            allura.tasks.mail_tasks.sendsimplemail.post(
+                toaddr=email,
                 fromaddr=config['forgemail.return_path'],
                 reply_to=config['forgemail.return_path'],
                 subject=subject,

http://git-wip-us.apache.org/repos/asf/allura/blob/2e1735cb/Allura/allura/tasks/export_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/export_tasks.py b/Allura/allura/tasks/export_tasks.py
index d50d22b..eb9ff4d 100644
--- a/Allura/allura/tasks/export_tasks.py
+++ b/Allura/allura/tasks/export_tasks.py
@@ -83,16 +83,18 @@ class BulkExport(object):
             'tools': exported_names,
             'not_exported_tools': list(set(tools) - set(exported_names)),
         }
+
         email = {
-            'sender': unicode(tg.config['forgemail.return_path']),
+            'toaddr': unicode(user._id),
             'fromaddr': unicode(tg.config['forgemail.return_path']),
+            'sender': unicode(tg.config['forgemail.return_path']),
             'reply_to': unicode(tg.config['forgemail.return_path']),
             'message_id': h.gen_message_id(),
-            'destinations': [unicode(user._id)],
             'subject': u'Bulk export for project %s completed' % project.shortname,
-            'text': tmpl.render(tmpl_context),
+            'text': tmpl.render(tmpl_context)
         }
-        mail_tasks.sendmail.post(**email)
+
+        mail_tasks.sendsimplemail.post(**email)
 
     def get_export_path(self, export_base_path, export_filename):
         """Create temporary directory for export files"""

http://git-wip-us.apache.org/repos/asf/allura/blob/2e1735cb/Allura/allura/tasks/mail_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index 9676842..4fce0d7 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -85,6 +85,10 @@ def route_email(
 @task
 def sendmail(fromaddr, destinations, text, reply_to, subject,
              message_id, in_reply_to=None, sender=None, references=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.
+    '''
     from allura import model as M
     addrs_plain = []
     addrs_html = []
@@ -157,6 +161,10 @@ def sendsimplemail(
         sender=None,
         references=None,
         cc=None):
+    '''
+    Send a single mail to the specified address.
+    It is best for single user notifications.
+    '''
     from allura import model as M
     if fromaddr is None:
         fromaddr = g.noreply
@@ -168,6 +176,17 @@ def sendsimplemail(
             fromaddr = g.noreply
         else:
             fromaddr = user.email_address_header()
+
+
+    if '@' not in toaddr:
+        log.warning('Looking up user with toaddr: %s', toaddr)
+        user = M.User.query.get(_id=ObjectId(toaddr), disabled=False)
+        if not user:
+            log.warning('Cannot find user with ID: %s', toaddr)
+            toaddr = g.noreply
+        else:
+            toaddr = user.email_address_header()
+
     htmlparser = HTMLParser.HTMLParser()
     plain_msg = mail_util.encode_email_part(htmlparser.unescape(text), 'plain')
     html_text = g.forge_markdown(email=True).convert(text)

http://git-wip-us.apache.org/repos/asf/allura/blob/2e1735cb/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index a200352..c5c0330 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -706,7 +706,7 @@ class TestPasswordReset(TestController):
         hash = user.get_tool_data('AuthPasswordReset', 'hash')
         assert hash is None
 
-    @patch('allura.tasks.mail_tasks.sendmail')
+    @patch('allura.tasks.mail_tasks.sendsimplemail')
     @patch('allura.lib.helpers.gen_message_id')
     def test_password_reset(self, gen_message_id, sendmail):
         user = M.User.query.get(username='test-admin')
@@ -740,7 +740,7 @@ To reset your password on %s, please visit the following URL:
 %s/auth/forgotten_password/%s''' % (config['site_name'], config['base_url'], hash)
 
         sendmail.post.assert_called_once_with(
-            destinations=[email._id],
+            toaddr=email._id,
             fromaddr=config['forgemail.return_path'],
             reply_to=config['forgemail.return_path'],
             subject='Allura Password recovery',
@@ -752,7 +752,7 @@ To reset your password on %s, please visit the following URL:
         assert_equal(hash, '')
         assert_equal(hash_expiry, '')
 
-    @patch('allura.tasks.mail_tasks.sendmail')
+    @patch('allura.tasks.mail_tasks.sendsimplemail')
     @patch('allura.lib.helpers.gen_message_id')
     def test_hash_expired(self, gen_message_id, sendmail):
         user = M.User.query.get(username='test-admin')

http://git-wip-us.apache.org/repos/asf/allura/blob/2e1735cb/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 97c7699..5dd70b6 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -516,7 +516,7 @@ class TestExportTasks(unittest.TestCase):
         # check notification
         M.MonQTask.run_ready()
         tasks = M.MonQTask.query.find(
-            dict(task_name='allura.tasks.mail_tasks.sendmail')).all()
+            dict(task_name='allura.tasks.mail_tasks.sendsimplemail')).all()
         assert_equal(len(tasks), 1)
         assert_equal(tasks[0].kwargs['subject'],
                      'Bulk export for project test completed')

http://git-wip-us.apache.org/repos/asf/allura/blob/2e1735cb/Allura/docs/api/tasks.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/api/tasks.rst b/Allura/docs/api/tasks.rst
index d49b8af..0ae3b1d 100644
--- a/Allura/docs/api/tasks.rst
+++ b/Allura/docs/api/tasks.rst
@@ -28,3 +28,9 @@
   .. automodule:: allura.tasks.export_tasks
 
         .. autofunction:: allura.tasks.export_tasks.bulk_export
+
+  .. automodule:: allura.tasks.mail_tasks
+
+        .. autofunction:: allura.tasks.mail_tasks.sendmail
+
+        .. autofunction:: allura.tasks.mail_tasks.sendsimplemail
\ No newline at end of file