Add User-Agent to SMTP integration (#181607)

This commit is contained in:
Manu
2026-09-08 08:11:26 +02:00
committed by GitHub
parent 178ab42316
commit 07e871579d
4 changed files with 26 additions and 6 deletions
+3
View File
@@ -26,6 +26,7 @@ from homeassistant.components.notify import (
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigSubentry
from homeassistant.const import (
APPLICATION_NAME,
CONF_DEBUG,
CONF_PASSWORD,
CONF_PORT,
@@ -35,6 +36,7 @@ from homeassistant.const import (
CONF_USERNAME,
CONF_VERIFY_SSL,
Platform,
__version__,
)
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@@ -300,6 +302,7 @@ class MailNotifyEntity(NotifyEntity):
email.utils.formataddr((self._subentry.title, self._subentry.unique_id)),
)
msg.add_header("X-Mailer", "Home Assistant")
msg.add_header("User-Agent", f"{APPLICATION_NAME}/{__version__}")
msg.add_header("Date", email.utils.format_datetime(dt_util.now()))
msg.add_header("Message-Id", email.utils.make_msgid())
+11
View File
@@ -94,6 +94,17 @@ def mock_randrange() -> Generator[None]:
yield
@pytest.fixture(name="version")
def mock_version() -> Generator[None]:
"""Mock Home Assistant version."""
with patch(
"homeassistant.components.smtp.notify.__version__",
"2026.10.0",
):
yield
@pytest.fixture(name="client_context")
def mock_client_context() -> Generator[None]:
"""Mock client_context."""
@@ -59,6 +59,7 @@
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
Message-Id: <177777777700.12345.12345678901234567890@mock>
@@ -76,6 +77,7 @@
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
Message-Id: <177777777700.12345.12345678901234567890@mock>
@@ -105,6 +107,7 @@
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
Message-Id: <177777777700.12345.12345678901234567890@mock>
@@ -148,6 +151,7 @@
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
Message-Id: <177777777700.12345.12345678901234567890@mock>
@@ -205,6 +209,7 @@
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
Message-Id: <177777777700.12345.12345678901234567890@mock>
@@ -234,6 +239,7 @@
From: Home Assistant <email@example.com>
To: Recipient <recipient@example.com>
X-Mailer: Home Assistant
User-Agent: HomeAssistant/2026.10.0
Date: Sat, 02 May 2026 20:09:37 -0700
Message-Id: <177777777700.12345.12345678901234567890@mock>
+6 -6
View File
@@ -225,7 +225,7 @@ async def test_notify_platform(
await snapshot_platform(hass, entity_registry, snapshot, config_entry.entry_id)
@pytest.mark.usefixtures("make_msgid", "smtp")
@pytest.mark.usefixtures("make_msgid", "smtp", "version")
@pytest.mark.freeze_time("2026-05-03T03:09:37+00:00")
async def test_notify_send_message(
hass: HomeAssistant,
@@ -338,7 +338,7 @@ async def test_legacy_notify_exception(
assert smtp.sendmail.call_count == 2
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange")
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange", "version")
@pytest.mark.freeze_time("2026-05-03T03:09:37+00:00")
async def test_smtp_send_message(
hass: HomeAssistant,
@@ -378,7 +378,7 @@ async def test_smtp_send_message(
assert msg.as_string() == snapshot
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange")
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange", "version")
@pytest.mark.freeze_time("2026-05-03T03:09:37+00:00")
async def test_smtp_send_message_local_media_source(
hass: HomeAssistant,
@@ -419,7 +419,7 @@ async def test_smtp_send_message_local_media_source(
assert msg.as_string() == snapshot
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange")
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange", "version")
@pytest.mark.freeze_time("2026-05-03T03:09:37+00:00")
async def test_smtp_send_message_camera_source(
hass: HomeAssistant,
@@ -465,7 +465,7 @@ async def test_smtp_send_message_camera_source(
assert msg.as_string() == snapshot
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange")
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange", "version")
@pytest.mark.freeze_time("2026-05-03T03:09:37+00:00")
async def test_smtp_send_message_image_source(
hass: HomeAssistant,
@@ -516,7 +516,7 @@ async def test_smtp_send_message_image_source(
assert msg.as_string() == snapshot
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange")
@pytest.mark.usefixtures("make_msgid", "smtp", "randrange", "version")
@pytest.mark.freeze_time("2026-05-03T03:09:37+00:00")
async def test_smtp_send_message_tts_source(
hass: HomeAssistant,