MCPcopy
hub / github.com/django/django / message_from_bytes

Function message_from_bytes

tests/mail/tests.py:110–122  ·  view source on GitHub ↗

email.message_from_bytes() using modern email.policy.default. Returns a modern email.message.EmailMessage.

(s)

Source from the content-addressed store, hash-verified

108
109
110def message_from_bytes(s):
111 """
112 email.message_from_bytes() using modern email.policy.default.
113 Returns a modern email.message.EmailMessage.
114 """
115 # The modern email parser has a bug with adjacent rfc2047 encoded-words.
116 # This doesn't affect django.core.mail (which doesn't parse messages),
117 # but it can confuse our tests that try to verify sent content by reparsing
118 # the generated message. Apply a workaround if needed.
119 message = _message_from_bytes(s, policy=policy.default)
120 if NEEDS_CPYTHON_128110_WORKAROUND and RFC2047_PREFIX.encode() in s:
121 _apply_cpython_128110_workaround(message, s)
122 return message
123
124
125class MailTestsMixin:

Calls 2

encodeMethod · 0.45

Tested by

no test coverage detected