Ignore deleted mails in IMAP unread count (#6394) (#6395)

Message deletion in IMAP is a two step process: first delete, then expunge.
Deleting a message just sets a flag that usually makes the mail client hide
the message. It is the expunge that actually removes the message.

Thus, exclude the deleted messages so that the unread count matches up with
that of most mail clients.
This commit is contained in:
Anders Melchiorsen 2017-03-05 17:15:25 +01:00 committed by Paulus Schoutsen
parent de038bae65
commit 660e777f01

View file

@ -85,7 +85,7 @@ class ImapSensor(Entity):
try:
self.connection.select()
self._unread_count = len(self.connection.search(
None, 'UnSeen')[1][0].split())
None, 'UnSeen UnDeleted')[1][0].split())
except imaplib.IMAP4.error:
_LOGGER.info("Connection to %s lost, attempting to reconnect",
self._server)