Browse Source

When decoding inbound emails, decode encoded headers. Fixes #420

pull/426/head
Pēteris Caune 4 years ago
parent
commit
66a1a108bf
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 17 additions and 1 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +4
    -1
      hc/api/management/commands/smtpd.py
  3. +12
    -0
      hc/api/tests/test_smtpd.py

+ 1
- 0
CHANGELOG.md View File

@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
- Don't allow duplicate team memberships
- When copying a check, copy all fields from the "Filtering Rules" dialog (#417)
- Fix missing Resume button (#421)
- When decoding inbound emails, decode encoded headers (#420)
## v1.16.0 - 2020-08-04


+ 4
- 1
hc/api/management/commands/smtpd.py View File

@ -1,5 +1,6 @@
import asyncore
import email
import email.policy
import re
from smtpd import SMTPServer
@ -41,7 +42,9 @@ def _process_message(remote_addr, mailfrom, mailto, data):
action = "success"
if check.subject or check.subject_fail:
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):
action = "success"
elif check.subject_fail and _match(subject, check.subject_fail):


+ 12
- 0
hc/api/tests/test_smtpd.py View File

@ -98,3 +98,15 @@ class SmtpdTestCase(BaseTestCase):
self.assertEqual(ping.scheme, "email")
self.assertEqual(ping.ua, "Email from [email protected]")
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", "[email protected]", self.email, body.encode("utf8"))
ping = Ping.objects.latest("id")
self.assertEqual(ping.scheme, "email")
self.assertEqual(ping.ua, "Email from [email protected]")
self.assertEqual(ping.kind, None)

Loading…
Cancel
Save