GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit b78bc3ff authored by Cecylia Bocovich's avatar Cecylia Bocovich

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 {}"
.format(msg['From']))
return True
else:
......@@ -206,7 +211,8 @@ class EmailParser(object):
try:
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'))
log.msg(
......
......@@ -289,6 +289,13 @@ class EmailServiceTests(unittest.TestCase):
">\n")
self.assertEqual(request["command"], "help")
def test_bounce(self):
ep = conftests.EmailParser(self.settings, "gettor@torproject.org")
request = ep.parse("From: MAILER-DAEMON@mx1.riseup.net\n"
"Subject: Undelivered Mail Returned to Sender\r\n"
"To: gettor@torproject.org\n osx en\n")
self.assertEqual(request, {})
if __name__ == "__main__":
unittest.main()
Markdown is supported
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