Merge pull request #47 from laarmen/multiline-header

compose: directly load the draft into the final EmailMessage object
This commit is contained in:
Aleks Kissinger 2024-06-10 09:47:39 -07:00 committed by GitHub
commit add030278c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,10 +27,12 @@ import email
import email.utils
import email.parser
import email.policy
import email.message
import mimetypes
import subprocess
from subprocess import PIPE, Popen, TimeoutExpired
import tempfile
import typing
import os
import re
@ -411,20 +413,15 @@ class SendmailThread(QThread):
def run(self) -> None:
try:
account = self.panel.account_name()
m = email.message_from_string(self.panel.message_string)
eml = email.message.EmailMessage(policy=email.policy.EmailPolicy(utf8=False))
attachments: List[str] = m.get_all('A', [])
# n.b. this kills duplicate headers. May want to revisit this if it causes problems.
for h in m.keys():
if h != 'A':
eml[h] = m[h]
eml = typing.cast(email.message.EmailMessage, email.message_from_string(
self.panel.message_string,
policy = email.policy.EmailPolicy(utf8=False)))
attachments: List[str] = eml.get_all('A', [])
del eml['A']
eml['Message-ID'] = email.utils.make_msgid()
eml['User-Agent'] = 'Dodo'
eml.set_content(m.get_payload())
# add a date if it's missing
if not "Date" in eml:
eml["Date"] = email.utils.formatdate(localtime=True)