[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [gettor/master] Ignore emails from Mail Delivery System
commit b78bc3ff922ea53d972f994e670dd3c39f97e5d0
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
Date: Fri May 22 16:36:36 2020 -0400
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.
---
gettor/parse/email.py | 8 +++++++-
tests/test_email_service.py | 7 +++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/gettor/parse/email.py b/gettor/parse/email.py
index 5a3e45e..d37614d 100644
--- a/gettor/parse/email.py
+++ b/gettor/parse/email.py
@@ -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(
diff --git a/tests/test_email_service.py b/tests/test_email_service.py
index 3803e79..a41669f 100644
--- a/tests/test_email_service.py
+++ b/tests/test_email_service.py
@@ -289,6 +289,13 @@ class EmailServiceTests(unittest.TestCase):
">\n")
self.assertEqual(request["command"], "help")
+ def test_bounce(self):
+ ep = conftests.EmailParser(self.settings, "gettor@xxxxxxxxxxxxxx")
+ request = ep.parse("From: MAILER-DAEMON@xxxxxxxxxxxxxx\n"
+ "Subject: Undelivered Mail Returned to Sender\r\n"
+ "To: gettor@xxxxxxxxxxxxxx\n osx en\n")
+
+ self.assertEqual(request, {})
if __name__ == "__main__":
unittest.main()
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits