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
Pipeline #35990 failed with stage
in 0 seconds
...@@ -2,12 +2,12 @@ getResultValue = context.portal_catalog.getResultValue ...@@ -2,12 +2,12 @@ getResultValue = context.portal_catalog.getResultValue
from Products.ERP5Type.Utils import Email_parseAddressHeader from Products.ERP5Type.Utils import Email_parseAddressHeader
result = [] result = set()
for _, recipient in Email_parseAddressHeader(text): for _, recipient in set(Email_parseAddressHeader(text)):
if recipient: if recipient:
email = getResultValue(url_string={'query':recipient, 'key':'ExactMatch'}, portal_type='Email', parent_portal_type='Person') email = getResultValue(url_string={'query':recipient, 'key':'ExactMatch'}, portal_type='Email', parent_portal_type='Person')
if email is None: if email is None:
email = getResultValue(url_string={'query':recipient, 'key':'ExactMatch'}, portal_type='Email', parent_portal_type='Organisation') email = getResultValue(url_string={'query':recipient, 'key':'ExactMatch'}, portal_type='Email', parent_portal_type='Organisation')
if email is not None: if email is not None:
result.append(email.getParentValue()) result.add(email.getParentValue())
return result return list(result)
...@@ -735,6 +735,8 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -735,6 +735,8 @@ class TestCRMMailIngestion(BaseTestCRM):
('me@erp5.org', ['person_module/me']), ('me@erp5.org', ['person_module/me']),
('me@erp5.org, he@erp5.org', ['person_module/me', 'person_module/he']), ('me@erp5.org, he@erp5.org', ['person_module/me', 'person_module/he']),
('Sender <sender@customer.com>', ['person_module/sender']), ('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: # tricks to confuse the e-mail parser:
# a comma in the name # a comma in the name
('"Sender," <sender@customer.com>, he@erp5.org', ['person_module/sender', ('"Sender," <sender@customer.com>, he@erp5.org', ['person_module/sender',
...@@ -750,9 +752,10 @@ class TestCRMMailIngestion(BaseTestCRM): ...@@ -750,9 +752,10 @@ class TestCRMMailIngestion(BaseTestCRM):
for header, expected_paths in expected_values: for header, expected_paths in expected_values:
paths = [entity.getRelativeUrl() paths = [entity.getRelativeUrl()
for entity in portal.Base_getEntityListFromFromHeader(header)] for entity in portal.Base_getEntityListFromFromHeader(header)]
self.assertEqual(paths, expected_paths, self.assertEqual(
'%r should return %r, but returned %r' % sorted(paths), sorted(expected_paths),
(header, expected_paths, paths)) '%r should return %r, but returned %r' % (header, expected_paths, paths)
)
def test_document_creation(self): def test_document_creation(self):
# CRM email ingestion creates a Mail Message in event_module # 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