More email address validation

This commit is contained in:
Kovid Goyal 2022-01-24 08:08:33 +05:30
parent 9c2c036702
commit a107534286
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 3 deletions

View File

@ -245,6 +245,10 @@ class SelectRecipients(QDialog): # {{{
if not to: if not to:
return error_dialog( return error_dialog(
self, _('Need address'), _('You must specify an address'), show=True) self, _('Need address'), _('You must specify an address'), show=True)
from email.utils import parseaddr
if not parseaddr(to)[-1] or '@' not in to:
return error_dialog(
self, _('Invalid email address'), _('The address {} is invalid').format(to), show=True)
formats = ','.join([x.strip().upper() for x in str(self.formats.text()).strip().split(',') if x.strip()]) formats = ','.join([x.strip().upper() for x in str(self.formats.text()).strip().split(',') if x.strip()])
if not formats: if not formats:
return error_dialog( return error_dialog(

View File

@ -150,7 +150,7 @@ class EmailAccounts(QAbstractTableModel): # {{{
na = as_unicode(value or '') na = as_unicode(value or '')
from email.utils import parseaddr from email.utils import parseaddr
addr = parseaddr(na)[-1] addr = parseaddr(na)[-1]
if not addr: if not addr or '@' not in na:
return False return False
self.accounts[na] = self.accounts.pop(account) self.accounts[na] = self.accounts.pop(account)
self.account_order[row] = na self.account_order[row] = na

View File

@ -68,8 +68,9 @@ class TestEmail(QDialog):
def run_test(self): def run_test(self):
from email.utils import parseaddr from email.utils import parseaddr
addr = parseaddr(self.to.text().strip())[-1] q = self.to.text().strip()
if not addr: addr = parseaddr(q)[-1]
if not addr or '@' not in q:
tb = f'{self.to.text().strip()} is not a valid email address' tb = f'{self.to.text().strip()} is not a valid email address'
else: else:
try: try: