If an email contains non ascii UTF-8 characters, eml.as_bytes() raises an ASCII encoding error, which prevents the email from being saved to the sent_dir of the mail account and subsequent tasks like reindexing notmutch and tagging the message as replied.
Both replacing as_bytes with as_string() and removing utf8=False (see here) in email Policy solves the problem. Both approaches seem to have the same effect on email encoding (RFC 2045 quoted encoding like =C3=A1 for “á”).
I wonder why utf8=False is explicitly set in the email policy, and also why as_bytes() is used for Maildir manipulation while as_string() is used to pipe the message to the subprocess.
It seems that every component of the modern email stack is perfectly happy with an email encoded using quoted Unicode.
I'm not an emailing expert, and I were suspecting there is a good reason utf-8 is explicitly disabled in mail policy so I extensively tested the saved Sent mail in the imap stack.
I tested it with mbsync <-> Dovecot, and then also fetched it with different user agents like thunderbird, alps and roundcube.
The email were displayed correctly everywhere.
If an email contains non ascii UTF-8 characters,
eml.as_bytes()raises an ASCII encoding error, which prevents the email from being saved to thesent_dirof the mail account and subsequent tasks like reindexing notmutch and tagging the message as replied.Both replacing
as_byteswithas_string()and removingutf8=False(see here) in email Policy solves the problem. Both approaches seem to have the same effect on email encoding (RFC 2045 quoted encoding like=C3=A1for “á”).I wonder why
utf8=Falseis explicitly set in the email policy, and also whyas_bytes()is used for Maildir manipulation whileas_string()is used to pipe the message to the subprocess.It seems that every component of the modern email stack is perfectly happy with an email encoded using quoted Unicode.
I'm not an emailing expert, and I were suspecting there is a good reason utf-8 is explicitly disabled in mail policy so I extensively tested the saved Sent mail in the imap stack.
I tested it with mbsync <-> Dovecot, and then also fetched it with different user agents like thunderbird, alps and roundcube.
The email were displayed correctly everywhere.