Skip to content

Commit

Permalink
[FIX] helpdesk_mgmt: format email when receive it from new message ma…
Browse files Browse the repository at this point in the history
…il gateway

Before, email was like '"Name" <name@company.com>'
Now, email is like 'name@company.com'
To field partner_email into model helpdesk.ticket
  • Loading branch information
mathben committed Jul 23, 2023
1 parent 7f7adf7 commit efecb5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from odoo import _, api, fields, models, tools
from odoo.exceptions import AccessError

Expand Down Expand Up @@ -206,6 +208,16 @@ def _track_template(self, tracking):
)
return res

def _extract_email(self, label):
if not label:
return ""
emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", label)
if len(emails) == 1:
return emails[0]
elif not emails:
return ""
return emails

@api.model
def message_new(self, msg, custom_values=None):
"""Override message_new from mail gateway so we can set correct
Expand All @@ -216,7 +228,7 @@ def message_new(self, msg, custom_values=None):
defaults = {
"name": msg.get("subject") or _("No Subject"),
"description": msg.get("body"),
"partner_email": msg.get("from"),
"partner_email": self._extract_email(msg.get("from")),
"partner_id": msg.get("author_id"),
}
defaults.update(custom_values)
Expand Down
1 change: 1 addition & 0 deletions helpdesk_mgmt/tests/test_helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_helpdesk_ticket_message_new(self):
"message_id": msg_id,
"subject": title,
"email_from": "Bob <bob@example.com>",
"from": "Bob <bob@example.com>",
"to": "jill@example.com",
"cc": "sally@example.com",
"recipients": "jill@example.com+sally@example.com",
Expand Down

0 comments on commit efecb5f

Please sign in to comment.