Commit b78bc3ff authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Ignore emails from Mail Delivery System

This ignores emails with the username "MAILER-DAEMON", a common email
for mail delivery systems. The goal of this is to avoid getting into a
loop with mail delivery system autoresponders after a bounced email.
parent 3670e782
......@@ -84,6 +84,11 @@ class EmailParser(object):
"Email address normalized and validated.",
system="email parser"
# Add a check for auto-generated mail-daemon emails
if "mailer-daemon@" in norm_addr.lower():
raise AddressError("Received mail from Mail Delivery System {}"
return True
......@@ -206,7 +211,8 @@ class EmailParser(object):
self.validate(norm_addr, msg)
except AddressError as e:
log.message("Address error: {}".format(e.args))
log.msg("Address error: {}".format(e.args))
return {}
hid = hashlib.sha256(norm_addr.encode('utf-8'))
......@@ -289,6 +289,13 @@ class EmailServiceTests(unittest.TestCase):
self.assertEqual(request["command"], "help")
def test_bounce(self):
ep = conftests.EmailParser(self.settings, "")
request = ep.parse("From:\n"
"Subject: Undelivered Mail Returned to Sender\r\n"
"To:\n osx en\n")
self.assertEqual(request, {})
if __name__ == "__main__":
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment