@philcowans
You're right, this is weird and I'm not entirely sure what's going on. I was able to get it to fail with some combinations, pass with others, and thought I had it figured out until I tried some other cases and those contradicted what I thought I'd established.
As to what's going on - I have a guess, but I'm not confident about it. I think it might be triggering only when an #rfc2047 -encoded segment of the header field value either exceeds the message's policy's line length limit, or in some way crosses over that boundary (such as having leading unencoded ASCII without a whitespace break that would allow the line to fold before the encoded segment).
If this is the case, it looks like a bug to me, too. If it's still happening with the most recent version of Python, I'd say it needs fixing. I haven't tried anything past 3.11.x right now.
Only showing up using the EmailMessage class vs Message class is explainable; there are slight differences, and one is for legacy code compatibility.
Weird.
#Python #email #EmailModule #EmailMessage #encoding #encoded