dodo icon indicating copy to clipboard operation
dodo copied to clipboard

compose: directly load the draft into the final EmailMessage object

Open laarmen opened this issue 1 year ago • 2 comments

This simplifies the code as we don't have to copy the data over from the temporary Message object. The header copying in particular was failing when using multiline headers as allowed by RFC 822.

I'm guessing we could get into trouble with encoding though? Since I'm using UTF-8 everywhere it works fine for me.

laarmen avatar Apr 05 '24 11:04 laarmen

hmm, I'm not sure an object coming from typing.cast is going to have the correct behaviour when I call methods on EmailMessage unless Message and EmailMessage have exactly the same fields. It might work ok now, but it seems fragile to me.

akissinger avatar Apr 09 '24 12:04 akissinger

It's a workaround for the lack of flexibility of the type hints in the email module. email.message_from_string is hinted to always return email.Message, however it will actually return whatever the policy.message_factory is, which as documented here is EmailMessage by default.

Technically typing.cast doesn't do anything at runtime, it's just to fool whatever tool is doing typechecking.

laarmen avatar Apr 09 '24 13:04 laarmen