From 660e777f01e709f286889190a9713c0d970738eb Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Sun, 5 Mar 2017 17:15:25 +0100 Subject: [PATCH] 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. --- homeassistant/components/sensor/imap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/imap.py b/homeassistant/components/sensor/imap.py index 69fc2eb88a7..4d7f34ef682 100644 --- a/homeassistant/components/sensor/imap.py +++ b/homeassistant/components/sensor/imap.py @@ -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)