[FIX] ir_mail_server: Use IDNA for smtp_user
There is a user whose email login is "joe@examplé.com", notice the latin "é" in the domain. This domain is a valid IDNA-2008 domain but the smtplib of python is incompatible with such domain and raises a UnicodeError because the character is not ascii. Note the removed comment about bytestring is a leftover of a dark python2 age and is no more valid. Closes #61972 closes odoo/odoo#62026 X-original-commit: 89a1989bd271f49a9222d5c255e03d4877045621 Signed-off-by: Raphael Collet (rco) <rco@openerp.com> Signed-off-by: Julien Castiaux <Julien00859@users.noreply.github.com>
This commit is contained in:
@@ -15,6 +15,7 @@ import sys
|
||||
import threading
|
||||
|
||||
import html2text
|
||||
import idna
|
||||
|
||||
from odoo import api, fields, models, tools, _
|
||||
from odoo.exceptions import UserError
|
||||
@@ -131,7 +132,7 @@ class IrMailServer(models.Model):
|
||||
except UserError as e:
|
||||
# let UserErrors (messages) bubble up
|
||||
raise e
|
||||
except UnicodeError as e:
|
||||
except (UnicodeError, idna.core.InvalidCodepoint) as e:
|
||||
raise UserError(_("Invalid server name !\n %s", ustr(e)))
|
||||
except (gaierror, timeout) as e:
|
||||
raise UserError(_("No response received. Check server address and port number.\n %s", ustr(e)))
|
||||
@@ -233,12 +234,9 @@ class IrMailServer(models.Model):
|
||||
|
||||
if smtp_user:
|
||||
# Attempt authentication - will raise if AUTH service not supported
|
||||
# The user/password must be converted to bytestrings in order to be usable for
|
||||
# certain hashing schemes, like HMAC.
|
||||
# See also bug #597143 and python issue #5285
|
||||
smtp_user = pycompat.to_text(ustr(smtp_user))
|
||||
smtp_password = pycompat.to_text(ustr(smtp_password))
|
||||
connection.login(smtp_user, smtp_password)
|
||||
local, at, domain = smtp_user.rpartition('@')
|
||||
domain = idna.encode(domain).decode('ascii')
|
||||
connection.login(f"{local}{at}{domain}", smtp_password or '')
|
||||
|
||||
# Some methods of SMTP don't check whether EHLO/HELO was sent.
|
||||
# Anyway, as it may have been sent by login(), all subsequent usages should consider this command as sent.
|
||||
|
||||
Reference in New Issue
Block a user