fix(email): add required Date header to outbound mail
This commit is contained in:
parent
a9033c9220
commit
75b460bc94
3 changed files with 12 additions and 0 deletions
|
|
@ -28,6 +28,7 @@ from email.header import decode_header
|
|||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from email.utils import formatdate
|
||||
from email import encoders
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
|
@ -504,6 +505,7 @@ class EmailAdapter(BasePlatformAdapter):
|
|||
msg["In-Reply-To"] = original_msg_id
|
||||
msg["References"] = original_msg_id
|
||||
|
||||
msg["Date"] = formatdate(localtime=True)
|
||||
msg_id = f"<hermes-{uuid.uuid4().hex[:12]}@{self._address.split('@')[1]}>"
|
||||
msg["Message-ID"] = msg_id
|
||||
|
||||
|
|
@ -586,6 +588,7 @@ class EmailAdapter(BasePlatformAdapter):
|
|||
msg["In-Reply-To"] = original_msg_id
|
||||
msg["References"] = original_msg_id
|
||||
|
||||
msg["Date"] = formatdate(localtime=True)
|
||||
msg_id = f"<hermes-{uuid.uuid4().hex[:12]}@{self._address.split('@')[1]}>"
|
||||
msg["Message-ID"] = msg_id
|
||||
|
||||
|
|
|
|||
|
|
@ -488,6 +488,7 @@ class TestThreadContext(unittest.TestCase):
|
|||
self.assertEqual(send_call["Subject"], "Re: Project question")
|
||||
self.assertEqual(send_call["In-Reply-To"], "<original@test.com>")
|
||||
self.assertEqual(send_call["References"], "<original@test.com>")
|
||||
self.assertIn("Date", send_call)
|
||||
|
||||
def test_reply_does_not_double_re(self):
|
||||
"""If subject already has Re:, don't add another."""
|
||||
|
|
@ -519,6 +520,7 @@ class TestThreadContext(unittest.TestCase):
|
|||
|
||||
send_call = mock_server.send_message.call_args[0][0]
|
||||
self.assertEqual(send_call["Subject"], "Re: Hermes Agent")
|
||||
self.assertIn("Date", send_call)
|
||||
|
||||
|
||||
class TestSendMethods(unittest.TestCase):
|
||||
|
|
@ -889,6 +891,11 @@ class TestSendEmailStandalone(unittest.TestCase):
|
|||
self.assertEqual(result["platform"], "email")
|
||||
_, kwargs = mock_server.starttls.call_args
|
||||
self.assertIsInstance(kwargs["context"], ssl.SSLContext)
|
||||
send_call = mock_server.send_message.call_args[0][0]
|
||||
self.assertEqual(send_call["Subject"], "Hermes Agent")
|
||||
self.assertIn("Date", send_call)
|
||||
self.assertEqual(send_call["To"], "user@test.com")
|
||||
self.assertEqual(send_call["From"], "hermes@test.com")
|
||||
|
||||
@patch.dict(os.environ, {
|
||||
"EMAIL_ADDRESS": "hermes@test.com",
|
||||
|
|
|
|||
|
|
@ -1075,6 +1075,7 @@ async def _send_email(extra, chat_id, message):
|
|||
"""Send via SMTP (one-shot, no persistent connection needed)."""
|
||||
import smtplib
|
||||
from email.mime.text import MIMEText
|
||||
from email.utils import formatdate
|
||||
|
||||
address = extra.get("address") or os.getenv("EMAIL_ADDRESS", "")
|
||||
password = os.getenv("EMAIL_PASSWORD", "")
|
||||
|
|
@ -1092,6 +1093,7 @@ async def _send_email(extra, chat_id, message):
|
|||
msg["From"] = address
|
||||
msg["To"] = chat_id
|
||||
msg["Subject"] = "Hermes Agent"
|
||||
msg["Date"] = formatdate(localtime=True)
|
||||
|
||||
server = smtplib.SMTP(smtp_host, smtp_port)
|
||||
server.starttls(context=ssl.create_default_context())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue