The test email backend (locmem) should perform more validation of messages
|Reported by:||Bruno Renié||Owned by:||nobody|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
locmem email backend only stores
EmailMessage instances on
mail.outbox, and does not perform as much validation as other backends.
In particular, calling
.message() on an
EmailMessage instance creates a
SafeMIMEText object which forbids multiline headers. All email backends call
.message() except for the
locmem backend. This is a opportunity for deployment surprises where sending an email would work during the tests but not in production if the subject is constructed using a template that has an EOL marker at the end of the file.
The attached patch naively calls .message() on each outgoing message to trigger this validation. This should be backwards-compatible since that error would be raised anyways when sending emails with a proper backend.
An alternative solution to this issue (email subjects ending with a newline) could be to strip all headers but this is a more intrusive change.