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:38 UTC
[3/3] git commit: [#6328] ticket:465 Fix references header and test
[#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')