forked from GithubBackups/healthchecks
When decoding inbound emails, decode encoded headers. Fixes #420
This commit is contained in:
parent
bd98174d4c
commit
66a1a108bf
@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Don't allow duplicate team memberships
|
- Don't allow duplicate team memberships
|
||||||
- When copying a check, copy all fields from the "Filtering Rules" dialog (#417)
|
- When copying a check, copy all fields from the "Filtering Rules" dialog (#417)
|
||||||
- Fix missing Resume button (#421)
|
- Fix missing Resume button (#421)
|
||||||
|
- When decoding inbound emails, decode encoded headers (#420)
|
||||||
|
|
||||||
## v1.16.0 - 2020-08-04
|
## v1.16.0 - 2020-08-04
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import asyncore
|
import asyncore
|
||||||
import email
|
import email
|
||||||
|
import email.policy
|
||||||
import re
|
import re
|
||||||
from smtpd import SMTPServer
|
from smtpd import SMTPServer
|
||||||
|
|
||||||
@ -41,7 +42,9 @@ def _process_message(remote_addr, mailfrom, mailto, data):
|
|||||||
action = "success"
|
action = "success"
|
||||||
if check.subject or check.subject_fail:
|
if check.subject or check.subject_fail:
|
||||||
action = "ign"
|
action = "ign"
|
||||||
subject = email.message_from_string(data).get("subject", "")
|
# Specify policy, the default policy does not decode encoded headers:
|
||||||
|
parsed = email.message_from_string(data, policy=email.policy.SMTP)
|
||||||
|
subject = parsed.get("subject", "")
|
||||||
if check.subject and _match(subject, check.subject):
|
if check.subject and _match(subject, check.subject):
|
||||||
action = "success"
|
action = "success"
|
||||||
elif check.subject_fail and _match(subject, check.subject_fail):
|
elif check.subject_fail and _match(subject, check.subject_fail):
|
||||||
|
@ -98,3 +98,15 @@ class SmtpdTestCase(BaseTestCase):
|
|||||||
self.assertEqual(ping.scheme, "email")
|
self.assertEqual(ping.scheme, "email")
|
||||||
self.assertEqual(ping.ua, "Email from foo@example.org")
|
self.assertEqual(ping.ua, "Email from foo@example.org")
|
||||||
self.assertEqual(ping.kind, "fail")
|
self.assertEqual(ping.kind, "fail")
|
||||||
|
|
||||||
|
def test_it_handles_encoded_subject(self):
|
||||||
|
self.check.subject = "SUCCESS"
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
body = PAYLOAD_TMPL % "=?US-ASCII?B?W1NVQ0NFU1NdIEJhY2t1cCBjb21wbGV0ZWQ=?="
|
||||||
|
_process_message("1.2.3.4", "foo@example.org", self.email, body.encode("utf8"))
|
||||||
|
|
||||||
|
ping = Ping.objects.latest("id")
|
||||||
|
self.assertEqual(ping.scheme, "email")
|
||||||
|
self.assertEqual(ping.ua, "Email from foo@example.org")
|
||||||
|
self.assertEqual(ping.kind, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user