allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [1/2] git commit: [#7677] update mail tasks to handle actual ObjectId in addr params
Date Mon, 15 Sep 2014 18:47:23 GMT
Repository: allura
Updated Branches:
  refs/heads/db/7677 [created] 2be2ce626


[#7677] update mail tasks to handle actual ObjectId in addr params


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

Branch: refs/heads/db/7677
Commit: 64a05dcaef2572a238b452ac15712b131cac0994
Parents: 505174a
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Mon Sep 15 18:41:44 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Mon Sep 15 18:41:44 2014 +0000

----------------------------------------------------------------------
 Allura/allura/tasks/mail_tasks.py | 15 +++++++++++----
 Allura/allura/tests/test_tasks.py | 14 ++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/64a05dca/Allura/allura/tasks/mail_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/mail_tasks.py b/Allura/allura/tasks/mail_tasks.py
index 4fce0d7..110160d 100644
--- a/Allura/allura/tasks/mail_tasks.py
+++ b/Allura/allura/tasks/mail_tasks.py
@@ -88,6 +88,10 @@ def sendmail(fromaddr, destinations, text, reply_to, subject,
     '''
     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.
+
+    :param fromaddr: ObjectId or str(ObjectId) of user, or email address str
+    :param toaddr: ObjectId or str(ObjectId) of user, or email address str
+
     '''
     from allura import model as M
     addrs_plain = []
@@ -95,7 +99,7 @@ def sendmail(fromaddr, destinations, text, reply_to, subject,
     addrs_multi = []
     if fromaddr is None:
         fromaddr = g.noreply
-    elif '@' not in fromaddr:
+    elif not isinstance(fromaddr, basestring) or '@' not in fromaddr:
         log.warning('Looking up user with fromaddr: %s', fromaddr)
         user = M.User.query.get(_id=ObjectId(fromaddr), disabled=False)
         if not user:
@@ -164,11 +168,15 @@ def sendsimplemail(
     '''
     Send a single mail to the specified address.
     It is best for single user notifications.
+
+    :param fromaddr: ObjectId or str(ObjectId) of user, or email address str
+    :param toaddr: ObjectId or str(ObjectId) of user, or email address str
+
     '''
     from allura import model as M
     if fromaddr is None:
         fromaddr = g.noreply
-    elif '@' not in fromaddr:
+    elif not isinstance(fromaddr, basestring) or '@' not in fromaddr:
         log.warning('Looking up user with fromaddr: %s', fromaddr)
         user = M.User.query.get(_id=ObjectId(fromaddr), disabled=False)
         if not user:
@@ -177,8 +185,7 @@ def sendsimplemail(
         else:
             fromaddr = user.email_address_header()
 
-
-    if '@' not in toaddr:
+    if not isinstance(toaddr, basestring) or '@' 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:

http://git-wip-us.apache.org/repos/asf/allura/blob/64a05dca/Allura/allura/tests/test_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 5dd70b6..13d5c17 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -388,6 +388,20 @@ class TestMailTasks(unittest.TestCase):
             assert_in('CC: someone@example.com', body)
             assert_in('someone@example.com', rcpts)
 
+    def test_fromaddr_objectid_not_str(self):
+        c.user = M.User.by_username('test-admin')
+        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
+            mail_tasks.sendsimplemail(
+                fromaddr=c.user._id,
+                toaddr='test@mail.com',
+                text=u'This is a test',
+                reply_to=g.noreply,
+                subject=u'Test subject',
+                message_id=h.gen_message_id())
+            assert_equal(_client.sendmail.call_count, 1)
+            return_path, rcpts, body = _client.sendmail.call_args[0]
+            assert_in('From: "Test Admin" <test-admin@users.localhost>', body)
+
     @td.with_wiki
     def test_receive_email_ok(self):
         c.user = M.User.by_username('test-admin')


Mime
View raw message