From 66adc0742f529ae0bda7fabb4f2e287322b2cf87 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 3 Sep 2018 15:25:57 +0200 Subject: [PATCH] Check emails for validity Checks with reg expressions whether the emails provided could be real emails containing an @ and a . Fixes #13. --- massmail | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/massmail b/massmail index 87a9615..6523313 100755 --- a/massmail +++ b/massmail @@ -229,6 +229,15 @@ def parse_parameter_file(options): return keywords, email_count +# check the email address for validity + +def check_email_validity(addressToVerify): + match = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', addressToVerify) + + if match == None: + print('Bad Syntax') + raise ValueError('Bad Syntax') + def create_email_bodies(options, keywords, email_count, body): # find keywords and substitute with values # we need to create email_count bodies @@ -248,6 +257,7 @@ def add_email_headers(options, msgs): # we need to add the headers for emailaddr in msgs: + check_email_validity(str(emailaddr)) msg = msgs[emailaddr] msg['To'] = str(emailaddr) msg['From'] = email.header.Header(options['from'])