diff --git a/src/calibre/gui2/email.py b/src/calibre/gui2/email.py index b81f832336..5527226005 100644 --- a/src/calibre/gui2/email.py +++ b/src/calibre/gui2/email.py @@ -245,6 +245,10 @@ class SelectRecipients(QDialog): # {{{ if not to: return error_dialog( 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()]) if not formats: return error_dialog( diff --git a/src/calibre/gui2/preferences/emailp.py b/src/calibre/gui2/preferences/emailp.py index dcc48af9e8..79c8492961 100644 --- a/src/calibre/gui2/preferences/emailp.py +++ b/src/calibre/gui2/preferences/emailp.py @@ -150,7 +150,7 @@ class EmailAccounts(QAbstractTableModel): # {{{ na = as_unicode(value or '') from email.utils import parseaddr addr = parseaddr(na)[-1] - if not addr: + if not addr or '@' not in na: return False self.accounts[na] = self.accounts.pop(account) self.account_order[row] = na diff --git a/src/calibre/gui2/wizard/send_email.py b/src/calibre/gui2/wizard/send_email.py index ca9dae7d6f..8b43f52b9b 100644 --- a/src/calibre/gui2/wizard/send_email.py +++ b/src/calibre/gui2/wizard/send_email.py @@ -68,8 +68,9 @@ class TestEmail(QDialog): def run_test(self): from email.utils import parseaddr - addr = parseaddr(self.to.text().strip())[-1] - if not addr: + q = self.to.text().strip() + addr = parseaddr(q)[-1] + if not addr or '@' not in q: tb = f'{self.to.text().strip()} is not a valid email address' else: try: