Commit b11c5f58 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_crm: do not list twice a same user when ingesting an email

parent 78f80ad2
......@@ -2,12 +2,12 @@ getResultValue = context.portal_catalog.getResultValue
from Products.ERP5Type.Utils import Email_parseAddressHeader
result = []
for _, recipient in Email_parseAddressHeader(text):
result = set()
for _, recipient in set(Email_parseAddressHeader(text)):
if recipient:
email = getResultValue(url_string={'query':recipient, 'key':'ExactMatch'}, portal_type='Email', parent_portal_type='Person')
if email is None:
email = getResultValue(url_string={'query':recipient, 'key':'ExactMatch'}, portal_type='Email', parent_portal_type='Organisation')
if email is not None:
result.append(email.getParentValue())
return result
result.add(email.getParentValue())
return list(result)
......@@ -735,6 +735,8 @@ class TestCRMMailIngestion(BaseTestCRM):
('me@erp5.org', ['person_module/me']),
('me@erp5.org, he@erp5.org', ['person_module/me', 'person_module/he']),
('Sender <sender@customer.com>', ['person_module/sender']),
# title is also an email, it should return the person once, not twice
('sender@customer.com <sender@customer.com>', ['person_module/sender']),
# tricks to confuse the e-mail parser:
# a comma in the name
('"Sender," <sender@customer.com>, he@erp5.org', ['person_module/sender',
......@@ -750,9 +752,10 @@ class TestCRMMailIngestion(BaseTestCRM):
for header, expected_paths in expected_values:
paths = [entity.getRelativeUrl()
for entity in portal.Base_getEntityListFromFromHeader(header)]
self.assertEqual(paths, expected_paths,
'%r should return %r, but returned %r' %
(header, expected_paths, paths))
self.assertEqual(
sorted(paths), sorted(expected_paths),
'%r should return %r, but returned %r' % (header, expected_paths, paths)
)
def test_document_creation(self):
# CRM email ingestion creates a Mail Message in event_module
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment