mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 03:41:05 -05:00
Add inbound mail handling
Add normalized event, signal, and webhooks for inbound mail. Closes #43 Closes #86
This commit is contained in:
@@ -8,6 +8,7 @@ import warnings
|
||||
from base64 import b64decode
|
||||
from contextlib import contextmanager
|
||||
|
||||
import six
|
||||
from django.test import Client
|
||||
|
||||
|
||||
@@ -35,6 +36,12 @@ def decode_att(att):
|
||||
return b64decode(att.encode('ascii'))
|
||||
|
||||
|
||||
def rfc822_unfold(text):
|
||||
# "Unfolding is accomplished by simply removing any CRLF that is immediately followed by WSP"
|
||||
# (WSP is space or tab, and per email.parser semantics, we allow CRLF, CR, or LF endings)
|
||||
return re.sub(r'(\r\n|\r|\n)(?=[ \t])', "", text)
|
||||
|
||||
|
||||
#
|
||||
# Sample files for testing (in ./test_files subdir)
|
||||
#
|
||||
@@ -133,11 +140,18 @@ class AnymailTestMixin:
|
||||
except TypeError:
|
||||
return self.assertRegexpMatches(*args, **kwargs) # Python 2
|
||||
|
||||
def assertEqualIgnoringWhitespace(self, first, second, msg=None):
|
||||
# Useful for message/rfc822 attachment tests
|
||||
self.assertEqual(first.replace(b'\n', b'').replace(b' ', b''),
|
||||
second.replace(b'\n', b'').replace(b' ', b''),
|
||||
msg)
|
||||
def assertEqualIgnoringHeaderFolding(self, first, second, msg=None):
|
||||
# Unfold (per RFC-8222) all text first and second, then compare result.
|
||||
# Useful for message/rfc822 attachment tests, where various Python email
|
||||
# versions handled folding slightly differently.
|
||||
# (Technically, this is unfolding both headers and (incorrectly) bodies,
|
||||
# but that doesn't really affect the tests.)
|
||||
if isinstance(first, six.binary_type) and isinstance(second, six.binary_type):
|
||||
first = first.decode('utf-8')
|
||||
second = second.decode('utf-8')
|
||||
first = rfc822_unfold(first)
|
||||
second = rfc822_unfold(second)
|
||||
self.assertEqual(first, second, msg)
|
||||
|
||||
|
||||
# Backported from python 3.5
|
||||
|
||||
Reference in New Issue
Block a user