compose: directly load the draft into the final EmailMessage object
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.
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.
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.