[FIX] mail: sanitize dots in generated mail alias
Create a company whoose name ends with a dot like "Bidule Inc.", change the company of the user to that new company, head to the Accouning module and create a new journal of type purchase. Traceback because the generated mail alias for that journal uses the company name and that the local-part of an email cannot ends with a dot. From the RFC standpoint, the local-part of an email address (the part before the @, `john` in `"John Doe" <john@example.com>`, cannot begins with, ends with or contain following dots. The email sanitizing function have been updated so it takes care of the above requirement. See also #61811 opw-2448692 closes odoo/odoo#69864 X-original-commit: f0e840ae6db387e1dfc99cc21e09d84eb126e7b9 Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
This commit is contained in:
@@ -161,6 +161,7 @@ class Alias(models.Model):
|
||||
""" Cleans and sanitizes the alias name """
|
||||
sanitized_name = remove_accents(name).lower().split('@')[0]
|
||||
sanitized_name = re.sub(r'[^\w+.]+', '-', sanitized_name)
|
||||
sanitized_name = re.sub(r'^\.+|\.+$|\.+(?=\.)', '', sanitized_name)
|
||||
sanitized_name = sanitized_name.encode('ascii', errors='replace').decode()
|
||||
return sanitized_name
|
||||
|
||||
|
||||
@@ -122,6 +122,13 @@ class TestMailAlias(TestMailCommon):
|
||||
with self.assertRaises(exceptions.ValidationError):
|
||||
record.write({'alias_defaults': "{'custom_field': brokendict"})
|
||||
|
||||
def test_alias_sanitize(self):
|
||||
alias = self.env['mail.alias'].create({
|
||||
'alias_model_id': self.env['ir.model']._get('mail.test.container').id,
|
||||
'alias_name': 'bidule...inc.',
|
||||
})
|
||||
self.assertEqual(alias.alias_name, 'bidule.inc', 'Emails cannot start or end with a dot, there cannot be a sequence of dots.')
|
||||
|
||||
def test_alias_setup(self):
|
||||
alias = self.env['mail.alias'].create({
|
||||
'alias_model_id': self.env['ir.model']._get('mail.test.container').id,
|
||||
|
||||
Reference in New Issue
Block a user