Patch stdlib email compat32 policy to default to CRLF line endings.
Project description
Default to CRLF policy for compat32 emails
This is a minimal package. It patches the standard lib, so that it defaults to using \r\n as line endings, instead of the standard lib default \n.
Doing so makes emitted emails standards compliant.
Moreover, doing so avoids getting corrupted emails delivered when relaying emails via outlook.com or office365.com.
The problem this package fixes, shows up as quoted-printable soft line endings =\n getting transformed into encoded equals signs =3D plus the removal of the first character following the newline. If you have URLs straddling a newline, those will not be valid anymore. But also normal text gets broken.
Email policies
We patch the Compat32 policy class and its compat32 instance. There are other policies, like the EmailPolicy class (using \n as line separator) and its SMTP instance (using \r\n as line separator). We do not touch those.
Quoting from the email.policy documentation:
There is a default policy used by all classes in the email package. For all of the parser classes and the related convenience functions, and for the Message class, this is the Compat32 policy, via its corresponding pre-defined instance compat32. This policy provides for complete backward compatibility (in some cases, including bug compatibility) with the pre-Python3.3 version of the email package.
The default value for the policy keyword to EmailMessage is the EmailPolicy policy, via its pre-defined instance default.
Why patch the standard lib, instead of fixing your own code?
Because to fix your own code, you’d have to ensure to override the default policy in every single instantiation of every Message or MIMEText or any of the other constructors which default to the compat32 policy without carriage returns.
Instead, you now can simply add emailcompat32crlf to your project dependencies and import it. Done.
If you are using Plone: we register an autoinclude entry point, so you do not even need to import it.
Changelog
1.0.3 (2024-06-03)
Register z3c.autoinclude.plugin entry point for Plone. This imports the package automatically on startup. This entry point is ignored when you don’t use Plone.
1.0.2 (2024-05-31)
Fix possible import error.
1.0.1 (2024-05-31)
Fix several problems in initial release.
1.0.0 (2024-05-31)
Initial release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for emailcompat32crlf-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37708094bf8aaeb2f2445229524580682d4ba1a1a6e7e9eb60f90a5a27031b4b |
|
MD5 | 71c69465e5849114be2e06a9054b96e2 |
|
BLAKE2b-256 | 70e6e6fd3ac7d3b67d285993efe803d26ce52461da3c7feb34c0e3c3962d15ba |