Re-read last imap_email_content email when no change (#36065)

This commit is contained in:
isk0001y authored and Franck Nijhof committed 2020-05-26 12:11:11 +02:00
1 parent 179e601966
commit b6c519e5df
1 file changed
+11
@@ -103,6 +103,8 @@ class EmailReader:
if message_data is None:
return None
if message_data[0] is None:
return None
raw_email = message_data[0][1]
email_message = email.message_from_bytes(raw_email)
return email_message
@@ -126,13 +128,22 @@ class EmailReader:
self._last_id = int(message_uid)
return self._fetch_message(message_uid)
return self._fetch_message(str(self._last_id))
except imaplib.IMAP4.error:
_LOGGER.info("Connection to %s lost, attempting to reconnect", self._server)
try:
self.connect()
_LOGGER.info(
"Reconnect to %s succeeded, trying last message", self._server
)
if self._last_id is not None:
return self._fetch_message(str(self._last_id))
except imaplib.IMAP4.error:
_LOGGER.error("Failed to reconnect")
return None
class EmailContentSensor(Entity):
"""Representation of an EMail sensor."""