+class EmailAddressCheck:\r
+ """Checks an email address."""\r
+\r
+ def __init__(self, email, description):\r
+ self.ok = True\r
+\r
+ if email is None:\r
+ self.error('Email address is missing!')\r
+ return\r
+ if description is None:\r
+ self.error('Email description is missing!')\r
+ return\r
+\r
+ self.description = "'" + description + "'"\r
+ self.check_email_address(email)\r
+\r
+ def error(self, *err):\r
+ if self.ok and Verbose.level > Verbose.ONELINE:\r
+ print('The ' + self.description + ' email address is not valid:')\r
+ self.ok = False\r
+ if Verbose.level < Verbose.NORMAL:\r
+ return\r
+ count = 0\r
+ for line in err:\r
+ prefix = (' *', ' ')[count > 0]\r
+ print(prefix, line)\r
+ count += 1\r
+\r
+ email_re1 = re.compile(r'(?:\s*)(.*?)(\s*)<(.+)>\s*$',\r
+ re.MULTILINE|re.IGNORECASE)\r
+\r
+ def check_email_address(self, email):\r
+ email = email.strip()\r
+ mo = self.email_re1.match(email)\r
+ if mo is None:\r
+ self.error("Email format is invalid: " + email.strip())\r
+ return\r
+\r
+ name = mo.group(1).strip()\r
+ if name == '':\r
+ self.error("Name is not provided with email address: " +\r
+ email)\r
+ else:\r
+ quoted = len(name) > 2 and name[0] == '"' and name[-1] == '"'\r
+ if name.find(',') >= 0 and not quoted:\r
+ self.error('Add quotes (") around name with a comma: ' +\r
+ name)\r
+\r
+ if mo.group(2) == '':\r
+ self.error("There should be a space between the name and " +\r
+ "email address: " + email)\r
+\r
+ if mo.group(3).find(' ') >= 0:\r
+ self.error("The email address cannot contain a space: " +\r
+ mo.group(3))\r
+\r
+ if ' via Groups.Io' in name and mo.group(3).endswith('@groups.io'):\r
+ self.error("Email rewritten by lists DMARC / DKIM / SPF: " +\r
+ email)\r
+\r