mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Check if imap message text has a value instead of checking if its not None (#118901)
* Check if message_text has a value instead of checking if its not None * Strip message_text to ensure that its actually empty or not * Add test with multipart payload having empty plain text
This commit is contained in:
parent
4ec6ba445b
commit
cab58fa9b2
@ -195,13 +195,13 @@ class ImapMessage:
|
|||||||
):
|
):
|
||||||
message_untyped_text = str(part.get_payload())
|
message_untyped_text = str(part.get_payload())
|
||||||
|
|
||||||
if message_text is not None:
|
if message_text is not None and message_text.strip():
|
||||||
return message_text
|
return message_text
|
||||||
|
|
||||||
if message_html is not None:
|
if message_html:
|
||||||
return message_html
|
return message_html
|
||||||
|
|
||||||
if message_untyped_text is not None:
|
if message_untyped_text:
|
||||||
return message_untyped_text
|
return message_untyped_text
|
||||||
|
|
||||||
return str(self.email_message.get_payload())
|
return str(self.email_message.get_payload())
|
||||||
|
@ -59,6 +59,11 @@ TEST_CONTENT_TEXT_PLAIN = (
|
|||||||
b"Content-Transfer-Encoding: 7bit\r\n\r\nTest body\r\n"
|
b"Content-Transfer-Encoding: 7bit\r\n\r\nTest body\r\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TEST_CONTENT_TEXT_PLAIN_EMPTY = (
|
||||||
|
b'Content-Type: text/plain; charset="utf-8"\r\n'
|
||||||
|
b"Content-Transfer-Encoding: 7bit\r\n\r\n \r\n"
|
||||||
|
)
|
||||||
|
|
||||||
TEST_CONTENT_TEXT_BASE64 = (
|
TEST_CONTENT_TEXT_BASE64 = (
|
||||||
b'Content-Type: text/plain; charset="utf-8"\r\n'
|
b'Content-Type: text/plain; charset="utf-8"\r\n'
|
||||||
b"Content-Transfer-Encoding: base64\r\n\r\nVGVzdCBib2R5\r\n"
|
b"Content-Transfer-Encoding: base64\r\n\r\nVGVzdCBib2R5\r\n"
|
||||||
@ -108,6 +113,15 @@ TEST_CONTENT_MULTIPART = (
|
|||||||
+ b"\r\n--Mark=_100584970350292485166--\r\n"
|
+ b"\r\n--Mark=_100584970350292485166--\r\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TEST_CONTENT_MULTIPART_EMPTY_PLAIN = (
|
||||||
|
b"\r\nThis is a multi-part message in MIME format.\r\n"
|
||||||
|
b"\r\n--Mark=_100584970350292485166\r\n"
|
||||||
|
+ TEST_CONTENT_TEXT_PLAIN_EMPTY
|
||||||
|
+ b"\r\n--Mark=_100584970350292485166\r\n"
|
||||||
|
+ TEST_CONTENT_HTML
|
||||||
|
+ b"\r\n--Mark=_100584970350292485166--\r\n"
|
||||||
|
)
|
||||||
|
|
||||||
TEST_CONTENT_MULTIPART_BASE64 = (
|
TEST_CONTENT_MULTIPART_BASE64 = (
|
||||||
b"\r\nThis is a multi-part message in MIME format.\r\n"
|
b"\r\nThis is a multi-part message in MIME format.\r\n"
|
||||||
b"\r\n--Mark=_100584970350292485166\r\n"
|
b"\r\n--Mark=_100584970350292485166\r\n"
|
||||||
@ -155,6 +169,18 @@ TEST_FETCH_RESPONSE_TEXT_PLAIN = (
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TEST_FETCH_RESPONSE_TEXT_PLAIN_EMPTY = (
|
||||||
|
"OK",
|
||||||
|
[
|
||||||
|
b"1 FETCH (BODY[] {"
|
||||||
|
+ str(len(TEST_MESSAGE + TEST_CONTENT_TEXT_PLAIN_EMPTY)).encode("utf-8")
|
||||||
|
+ b"}",
|
||||||
|
bytearray(TEST_MESSAGE + TEST_CONTENT_TEXT_PLAIN_EMPTY),
|
||||||
|
b")",
|
||||||
|
b"Fetch completed (0.0001 + 0.000 secs).",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
TEST_FETCH_RESPONSE_TEXT_PLAIN_ALT = (
|
TEST_FETCH_RESPONSE_TEXT_PLAIN_ALT = (
|
||||||
"OK",
|
"OK",
|
||||||
[
|
[
|
||||||
@ -249,6 +275,19 @@ TEST_FETCH_RESPONSE_MULTIPART = (
|
|||||||
b"Fetch completed (0.0001 + 0.000 secs).",
|
b"Fetch completed (0.0001 + 0.000 secs).",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
TEST_FETCH_RESPONSE_MULTIPART_EMPTY_PLAIN = (
|
||||||
|
"OK",
|
||||||
|
[
|
||||||
|
b"1 FETCH (BODY[] {"
|
||||||
|
+ str(len(TEST_MESSAGE_MULTIPART + TEST_CONTENT_MULTIPART_EMPTY_PLAIN)).encode(
|
||||||
|
"utf-8"
|
||||||
|
)
|
||||||
|
+ b"}",
|
||||||
|
bytearray(TEST_MESSAGE_MULTIPART + TEST_CONTENT_MULTIPART_EMPTY_PLAIN),
|
||||||
|
b")",
|
||||||
|
b"Fetch completed (0.0001 + 0.000 secs).",
|
||||||
|
],
|
||||||
|
)
|
||||||
TEST_FETCH_RESPONSE_MULTIPART_BASE64 = (
|
TEST_FETCH_RESPONSE_MULTIPART_BASE64 = (
|
||||||
"OK",
|
"OK",
|
||||||
[
|
[
|
||||||
|
@ -29,6 +29,7 @@ from .const import (
|
|||||||
TEST_FETCH_RESPONSE_MULTIPART,
|
TEST_FETCH_RESPONSE_MULTIPART,
|
||||||
TEST_FETCH_RESPONSE_MULTIPART_BASE64,
|
TEST_FETCH_RESPONSE_MULTIPART_BASE64,
|
||||||
TEST_FETCH_RESPONSE_MULTIPART_BASE64_INVALID,
|
TEST_FETCH_RESPONSE_MULTIPART_BASE64_INVALID,
|
||||||
|
TEST_FETCH_RESPONSE_MULTIPART_EMPTY_PLAIN,
|
||||||
TEST_FETCH_RESPONSE_NO_SUBJECT_TO_FROM,
|
TEST_FETCH_RESPONSE_NO_SUBJECT_TO_FROM,
|
||||||
TEST_FETCH_RESPONSE_TEXT_BARE,
|
TEST_FETCH_RESPONSE_TEXT_BARE,
|
||||||
TEST_FETCH_RESPONSE_TEXT_OTHER,
|
TEST_FETCH_RESPONSE_TEXT_OTHER,
|
||||||
@ -116,6 +117,7 @@ async def test_entry_startup_fails(
|
|||||||
(TEST_FETCH_RESPONSE_TEXT_OTHER, True),
|
(TEST_FETCH_RESPONSE_TEXT_OTHER, True),
|
||||||
(TEST_FETCH_RESPONSE_HTML, True),
|
(TEST_FETCH_RESPONSE_HTML, True),
|
||||||
(TEST_FETCH_RESPONSE_MULTIPART, True),
|
(TEST_FETCH_RESPONSE_MULTIPART, True),
|
||||||
|
(TEST_FETCH_RESPONSE_MULTIPART_EMPTY_PLAIN, True),
|
||||||
(TEST_FETCH_RESPONSE_MULTIPART_BASE64, True),
|
(TEST_FETCH_RESPONSE_MULTIPART_BASE64, True),
|
||||||
(TEST_FETCH_RESPONSE_BINARY, True),
|
(TEST_FETCH_RESPONSE_BINARY, True),
|
||||||
],
|
],
|
||||||
@ -129,6 +131,7 @@ async def test_entry_startup_fails(
|
|||||||
"other",
|
"other",
|
||||||
"html",
|
"html",
|
||||||
"multipart",
|
"multipart",
|
||||||
|
"multipart_empty_plain",
|
||||||
"multipart_base64",
|
"multipart_base64",
|
||||||
"binary",
|
"binary",
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user