[PATCH] check if the email address is correct
Carl Chenet
carl.chenet at ohmytux.com
Thu Jun 4 22:30:23 UTC 2009
---
bin/reportbug | 23 +++++++++++++++++------
reportbug/utils.py | 14 ++++++++++++++
2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/bin/reportbug b/bin/reportbug
index 409c505..8966118 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -489,12 +489,17 @@ def offer_configuration(options):
if isinstance(realname, str):
realname = realname.decode(charset, 'replace')
- from_addr = ui.get_string(
- 'Which of your email addresses should be used when sending bug '
- 'reports? (Note that this address will be visible in the bug tracking '
- 'system, so you may want to use a webmail address or another address '
- 'with good spam filtering capabilities.)',
- default=(options.email or def_email), force_prompt=True)
+ is_addr_ok = False
+ while is_addr_ok != True:
+ from_addr = ui.get_string(
+ 'Which of your email addresses should be used when sending bug '
+ 'reports? (Note that this address will be visible in the bug tracking '
+ 'system, so you may want to use a webmail address or another address '
+ 'with good spam filtering capabilities.)',
+ default=(options.email or def_email), force_prompt=True)
+ is_addr_ok = utils.check_email_addr(from_addr)
+ if not is_addr_ok:
+ ewrite('Your email address is not valid; please try another one.\n')
stupidmode = not ui.yes_no(
'Do you have a "mail transport agent" (MTA) like Exim, Postfix or '
@@ -844,6 +849,12 @@ def main():
# check if attachment files exist, else exiting
# all are checked, and it doesn't exit at the first missing
+
+ if options.email:
+ if not utils.check_email_addr(options.email):
+ ewrite('Your email address is not valid; exiting.\n')
+ sys.exit(1)
+
if options.attachments:
any_missing = False
for attachment in options.attachments:
diff --git a/reportbug/utils.py b/reportbug/utils.py
index fac6e8b..0da7c4f 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -208,6 +208,20 @@ def find_rewritten(username):
print 'Invalid entry in %s' % filename
return None
+def check_email_addr(addr):
+ if '@' not in addr:
+ return False
+ if addr.count('@') != 1:
+ return False
+ localpart, domainpart = addr.split('@')
+ if localpart.startswith('.') or localpart.endswith('.'):
+ return False
+ if '.' not in domainpart:
+ return False
+ if domainpart.startswith('.') or domainpart.endswith('.'):
+ return False
+ return True
+
def get_email_addr(addr):
addr = rfc822.AddressList(addr)
return addr.addresslist[0]
--
1.5.4.3
--=-RoyVZfc4pZ3fLP1UODwv--
More information about the Reportbug-maint
mailing list