Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imap_content sensor not updating #93092

Closed
talormanda opened this issue May 15, 2023 · 32 comments · Fixed by #93119
Closed

imap_content sensor not updating #93092

talormanda opened this issue May 15, 2023 · 32 comments · Fixed by #93119
Assignees

Comments

@talormanda
Copy link

talormanda commented May 15, 2023

The problem

  1. My IMAP sensor "sensor.imap_aaronautomation88" is updating to show 1 new email is present:
    image

  2. However, when I look at my imap_content sensor "sensor.imap_content", it is not updating the show the latest email. If I go to the Home Assistant devices page, go to the IMAP entity, and hit "reload", the "sensor.imap_content" instantly updates and my automations begin to trigger:
    image

  3. After a reboot of Home Assistant, it works without having to reload the integration for 1 email. Then, when the 2nd email comes in, it stops updating the "sensor.imap_content". But then other times, it seems to work fine randomly.

What version of Home Assistant Core has the issue?

2023.5.3

What was the last working version of Home Assistant Core?

2023.5.2

What type of installation are you running?

Home Assistant OS

Integration causing the issue

imap

Link to integration documentation on our website

https://www.home-assistant.io/integrations/imap/

Diagnostics information

No response

Example YAML snippet

This is the code in my configurations.yaml file for the "sensor.imap_content":

template:
  - trigger:
      - platform: event
        event_type: "imap_content"
        id: "custom_event"
    sensor:
      - name: imap_content
        state: "{{ trigger.event.data['subject'] }}"
        attributes:
          message: "{{ trigger.event.data['text'] }}"
          server: "{{ trigger.event.data['server'] }}"
          username: "{{ trigger.event.data['username'] }}"
          search: "{{ trigger.event.data['search'] }}"
          folder: "{{ trigger.event.data['folder'] }}"
          sender: "{{ trigger.event.data['sender'] }}"
          date: "{{ trigger.event.data['date'] }}"
          subject: "{{ trigger.event.data['subject'] }}"
          to: "{{ trigger.event.data['headers']['Delivered-To'][0] }}"
          subject2: "{{ trigger.event.data['headers']['Subject'][0] }}"
          return_Path: "{{ trigger.event.data['headers']['Return-Path'][0] }}"
          received-first: "{{ trigger.event.data['headers']['Received'][0] }}"
          received-last: "{{ trigger.event.data['headers']['Received'][-1] }}"

Anything in the logs that might be useful for us?

2023-05-15 07:14:18.016 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF8 OK Success\r\n'
2023-05-15 07:14:18.016 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF8 OK Success'
2023-05-15 07:14:18.023 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Message processed, sender: email1@gmail.com, subject: subject 5
2023-05-15 07:14:18.023 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 07:14:18.051 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF9 IDLE\r\n'
2023-05-15 07:14:18.170 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 07:14:18.170 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'
2023-05-15 07:14:33.186 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* 1 FETCH (UID 714 FLAGS (\\Seen))\r\n'
2023-05-15 07:14:33.187 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DONE\r\n'
2023-05-15 07:14:33.310 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF9 OK IDLE terminated (Success)\r\n'
2023-05-15 07:14:33.311 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF9 OK IDLE terminated (Success)'
2023-05-15 07:14:33.314 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF10 NOOP\r\n'
2023-05-15 07:14:33.441 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF10 OK Success\r\n'
2023-05-15 07:14:33.441 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF10 OK Success'
2023-05-15 07:14:33.443 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF11 SEARCH CHARSET utf-8 UnSeen UnDeleted\r\n'
2023-05-15 07:14:33.572 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* SEARCH\r\nDFEF11 OK SEARCH completed (Success)\r\n'
2023-05-15 07:14:33.573 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF11 OK SEARCH completed (Success)'
2023-05-15 07:14:33.575 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 07:14:33.583 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF12 IDLE\r\n'
2023-05-15 07:14:33.706 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 07:14:33.706 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'
2023-05-15 07:14:38.715 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* 1 EXPUNGE\r\n* 0 EXISTS\r\n'
2023-05-15 07:14:38.716 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DONE\r\n'
2023-05-15 07:14:38.837 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF12 OK IDLE terminated (Success'
2023-05-15 07:14:38.838 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b')\r\n'
2023-05-15 07:14:38.838 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF12 OK IDLE terminated (Success)'
2023-05-15 07:14:38.843 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF13 NOOP\r\n'
2023-05-15 07:14:38.966 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF13 OK Success\r\n'
2023-05-15 07:14:38.966 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF13 OK Success'
2023-05-15 07:14:38.970 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF14 SEARCH CHARSET utf-8 UnSeen UnDeleted\r\n'
2023-05-15 07:14:39.090 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* SEARCH\r\nDFEF14 OK SEARCH complet'
2023-05-15 07:14:39.090 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'ed (Success)\r\n'
2023-05-15 07:14:39.090 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF14 OK SEARCH completed (Success)'
2023-05-15 07:14:39.091 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 07:14:39.092 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF15 IDLE\r\n'
2023-05-15 07:14:39.217 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 07:14:39.217 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'
2023-05-15 07:15:24.231 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* 1 EXISTS\r\n'
2023-05-15 07:15:24.233 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DONE\r\n'
2023-05-15 07:15:24.356 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF15 OK IDLE ter'
2023-05-15 07:15:24.357 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'minated (Success)\r\n'
2023-05-15 07:15:24.357 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF15 OK IDLE terminated (Success)'
2023-05-15 07:15:24.360 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF16 NOOP\r\n'
2023-05-15 07:15:24.481 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF16 OK Success\r\n'
2023-05-15 07:15:24.482 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF16 OK Success'
2023-05-15 07:15:24.486 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF17 SEARCH CHARSET utf-8 UnSeen UnDeleted\r\n'
2023-05-15 07:15:24.618 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* SEARCH 1\r\nDFEF17 OK SEARCH compl'
2023-05-15 07:15:24.618 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'eted (Success)\r\n'
2023-05-15 07:15:24.618 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF17 OK SEARCH completed (Success)'
2023-05-15 07:15:24.624 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 07:15:24.635 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF18 IDLE\r\n'
2023-05-15 07:15:24.764 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 07:15:24.764 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'
2023-05-15 07:15:44.781 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* 1 FETCH (UID 715 FLAGS (\\Seen))\r'
2023-05-15 07:15:44.781 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'\n'
2023-05-15 07:15:44.782 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DONE\r\n'
2023-05-15 07:15:44.909 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF18 OK IDLE terminated (Success)\r\n'
2023-05-15 07:15:44.909 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF18 OK IDLE terminated (Success)'
2023-05-15 07:15:44.910 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF19 NOOP\r\n'
2023-05-15 07:15:45.034 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF19 OK Success\r\n'
2023-05-15 07:15:45.035 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF19 OK Success'
2023-05-15 07:15:45.036 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF20 SEARCH CHARSET utf-8 UnSeen UnDeleted\r\n'
2023-05-15 07:15:45.165 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* SEARCH\r\nDFEF20 OK SEARCH complet'
2023-05-15 07:15:45.167 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'ed (Success)\r\n'
2023-05-15 07:15:45.167 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF20 OK SEARCH completed (Success)'
2023-05-15 07:15:45.169 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 07:15:45.184 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF21 IDLE\r\n'
2023-05-15 07:15:45.306 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 07:15:45.306 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'
2023-05-15 07:15:55.324 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* 1 FETCH (UID 715 FLAGS ())\r\n'
2023-05-15 07:15:55.326 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DONE\r\n'
2023-05-15 07:15:55.446 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF21 OK IDLE terminated (Success'
2023-05-15 07:15:55.447 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b')\r\n'
2023-05-15 07:15:55.447 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF21 OK IDLE terminated (Success)'
2023-05-15 07:15:55.449 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF22 NOOP\r\n'
2023-05-15 07:15:55.570 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'DFEF22 OK Success\r\n'
2023-05-15 07:15:55.570 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF22 OK Success'
2023-05-15 07:15:55.571 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF23 SEARCH CHARSET utf-8 UnSeen UnDeleted\r\n'
2023-05-15 07:15:55.699 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* SEARCH 1\r\nDFEF23 OK SEARCH compl'
2023-05-15 07:15:55.700 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'eted (Success)\r\n'
2023-05-15 07:15:55.700 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'DFEF23 OK SEARCH completed (Success)'
2023-05-15 07:15:55.701 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 07:15:55.709 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DFEF24 IDLE\r\n'
2023-05-15 07:15:55.834 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 07:15:55.835 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'

Additional information

redacted email addresses for privacy

@home-assistant
Copy link

Hey there @engrbm87, @jbouwh, mind taking a look at this issue as it has been labeled with an integration (imap) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of imap can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign imap Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


imap documentation
imap source
(message by IssueLinks)

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

What service is supplying your mailbox? (e.g. GMAIL). When is the sensor not updated?
The custom_event is at startup, during a reload, and when a new message is received. If the message ID is the same as the last message ID processed, the custom_event will not be fired.
I did not succeed to reproduce your issue. Could to turn on debug logging for imap.

logger:
  default: info
  logs:
    homeassistant.components.imap: debug

When the event is fired a message like ...

... 2023-05-15 11:21:24.781 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Message processed, sender: sender@example.com, subject: xxxxx`

... should be logged when a new message is processed or at startup/reload.

@talormanda
Copy link
Author

What service is supplying your mailbox? (e.g. GMAIL). When is the sensor not updated? The custom_event is at startup, during a reload, and when a new message is received. If the message ID is the same as the last message ID processed, the custom_event will not be fired. I did not succeed to reproduce your issue. Could to turn on debug logging for imap.

logger:
  default: info
  logs:
    homeassistant.components.imap: debug

When the event is fired a message like ...

... 2023-05-15 11:21:24.781 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Message processed, sender: sender@example.com, subject: xxxxx`

... should be logged when a new message is processed or at startup/reload.

I am using GMAIL. What was happening was I sent an email to the IMAP account. The "sensor.imap_aaronautomation88" would update from 0 to 1, and "sensor.imap_content" would change to show attributes from that email. I would then send a 2nd email to the IMAP account "sensor.imap_aaronautomation88", and it would update from 1 to 2, or 0 to 1 if I had cleared the first email...but then "sensor.imap_content" would not update...and hold onto the data from the old email. When I would reload the integration, "sensor.imap_content" would instantly update and show the new email. It was doing this all yesterday and this morning. Currently, I have an email with a subject called "this is a test subject new 6", and the "sensor.imap_content" is not updating to show that email, it is only displaying the old email before it.

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

The event will only be fired if the latest message changes, not if you read some older messages but the latest message has not changed.

@talormanda
Copy link
Author

talormanda commented May 15, 2023

The event will only be fired if the latest message changes, not if you read some older messages but the latest message has not changed.

The latest message IS changing though on my GMAIL account. In the below photo, the new email is in my inbox, and is the ONLY message in my inbox and unread, but is not showing on the imap_content on the left.

image

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

And if you are adding a new message it does not update? Does it update the count sensor?

@talormanda
Copy link
Author

talormanda commented May 15, 2023

And if you are adding a new message it does not update? Does it update the count sensor?

Yes, it updates the count sensor. I just reloaded the integration and now this is the imap_content:

image

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

I mean, if you send another message to the maibox (without reloading), is the count changed to 2 but the content sensor not updated?

@talormanda
Copy link
Author

talormanda commented May 15, 2023

I mean, if you send another message to the maibox (without reloading), is the count changed to 2 but the content sensor not updated?

Correct, the count will change from 1 to 2 if there is 1 message there, and another comes in. Or if there are 0 messages, it will update from 0 to 1, but the imap_content sensor will not update to show the message. It seems to happen more when it goes from 0 messages to 1 actually.

edit: actually it may only be happening when the count goes from 0 to 1. still testing it.

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

You could check your debug logging as I asked. It is important to known if the custom_event was fired or not.

@talormanda
Copy link
Author

talormanda commented May 15, 2023

You could check your debug logging as I asked. It is important to known if the custom_event was fired or not.

I think I may be onto it. Here is my reproduction steps:

  1. message count for "sensor.imap_aaronautomation88" is 0
  2. send 1 message, this causes "sensor.imap_aaronautomation88" to update to 1 and "sensor.imap_content" updates to show the message
  3. go into GMAIL inbox and mark the message as read, then remove it from the INBOX, this causes "sensor.imap_aaronautomation88" to update from 1 to 0
  4. send another email, this causes "sensor.imap_aaronautomation88" to update from 0 to 1
  5. "sensor.imap_content" does not update until the integration is reloaded

I will edit / comment when I can get the log for this. It seems right now that if the count goes from 1 to 2, 2 to 3, 3 to 4, this isn't happening.

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

So may be the message ID's (UID's) are being reused?

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

Can you test without clearing all messages (leave at least 1 message)

@talormanda
Copy link
Author

Can you test without clearing all messages (leave at least 1 message)

Yes, if I leave 1 message there, and send a new one, it comes in and updates from 1 to 2, and displays the imap_content attributes for the new email. If I clear out the oldest email and go from a count of 2 to 1 again, and send a new email, the count goes from 1 to 2 again, and imap_content updates correctly. So this may be an issue when the count is going from 0 to 1.

@talormanda
Copy link
Author

talormanda commented May 15, 2023

I just cleared my inbox so the message count went from 3 to 0. I sent a new email called "subject 16", it came through. and the message count went from 0 to 1. I cleared my inbox AGAIN, and sent another email called "subject 17", it came through and the message count went from 0 to 1. I cleared my inbox AGAIN and sent another email called "subject 18", the message count changed from 0 to 1, but it did not come through.

2023-05-15 08:10:17.949 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'JAMN46 OK Success\r\n'
2023-05-15 08:10:17.950 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'JAMN46 OK Success'
2023-05-15 08:10:17.958 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Message processed, sender: email@gmail.com, subject: subject 17
2023-05-15 08:10:17.959 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 08:10:17.980 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'JAMN47 IDLE\r\n'
2023-05-15 08:10:18.105 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 08:10:18.106 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'
2023-05-15 08:10:33.118 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* 1 EXPUNGE\r\n* 0 EXISTS\r\n'
2023-05-15 08:10:33.120 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DONE\r\n'
2023-05-15 08:10:33.246 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'JAMN47 OK IDLE terminated (Success)\r\n'
2023-05-15 08:10:33.247 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'JAMN47 OK IDLE terminated (Success)'
2023-05-15 08:10:33.247 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'JAMN48 NOOP\r\n'
2023-05-15 08:10:33.374 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'JAMN48 OK Success\r\n'
2023-05-15 08:10:33.374 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'JAMN48 OK Success'
2023-05-15 08:10:33.375 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'JAMN49 SEARCH CHARSET utf-8 X-GM-RAW "in:inbox from:email@email.edu OR from:email@gmail.com is:unread"\r\n'
2023-05-15 08:10:33.499 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* SEARCH\r\nJAMN49 OK SEARCH completed (Success)\r\n'
2023-05-15 08:10:33.500 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'JAMN49 OK SEARCH completed (Success)'
2023-05-15 08:10:33.501 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 08:10:33.515 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'JAMN50 IDLE\r\n'
2023-05-15 08:10:33.642 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 08:10:33.643 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'
2023-05-15 08:11:28.655 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* 1 EXISTS\r\n'
2023-05-15 08:11:28.655 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'DONE\r\n'
2023-05-15 08:11:28.782 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'JAMN50 OK IDLE ter'
2023-05-15 08:11:28.782 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'minated (Success)\r\n'
2023-05-15 08:11:28.782 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'JAMN50 OK IDLE terminated (Success)'
2023-05-15 08:11:28.783 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'JAMN51 NOOP\r\n'
2023-05-15 08:11:28.906 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'JAMN51 OK Success\r\n'
2023-05-15 08:11:28.906 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'JAMN51 OK Success'
2023-05-15 08:11:28.908 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'JAMN52 SEARCH CHARSET utf-8 X-GM-RAW "in:inbox from:email@email.edu OR from:email@gmail.com is:unread"\r\n'
2023-05-15 08:11:29.044 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'* SEARCH 1\r\nJAMN52 OK SEARCH compl'
2023-05-15 08:11:29.044 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'eted (Success)\r\n'
2023-05-15 08:11:29.044 DEBUG (MainThread) [aioimaplib.aioimaplib] tagged status b'JAMN52 OK SEARCH completed (Success)'
2023-05-15 08:11:29.045 DEBUG (MainThread) [homeassistant.components.imap.coordinator] Manually updated imap data
2023-05-15 08:11:29.055 DEBUG (MainThread) [aioimaplib.aioimaplib] Sending : b'JAMN53 IDLE\r\n'
2023-05-15 08:11:29.177 DEBUG (MainThread) [aioimaplib.aioimaplib] Received : b'+ idling\r\n'
2023-05-15 08:11:29.177 DEBUG (MainThread) [aioimaplib.aioimaplib] continuation line -- assuming IDLE is active : b'+ idling'

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

Thnx, I'll dive deeper into this and see if I can supply a fix for this case.

@talormanda
Copy link
Author

Thnx, I'll dive deeper into this and see if I can supply a fix for this case.

I'm uploading a video showing this. Give me a moment.

@talormanda
Copy link
Author

talormanda commented May 15, 2023

Here is a video detailing the issue: https://www.youtube.com/watch?v=bTBALUC7DWM

Essentially when the email count goes from 0 to 1, clear all messages, then your count goes from 0 to 1 again, it will not update the imap_content sensor (or whatever you named your sensor). But...if you reload the configuration, it instantly updates it and works, for some reason.

@jbouwh
Copy link
Contributor

jbouwh commented May 15, 2023

Thanks for your help. I have opened a PR that should fix your issue. It will ensure that the last ID is reset to None when there is an update showing now messages. This will en sure the event is re-triggered when a new message comes in that might have the same UID (e.g. 1)

@talormanda
Copy link
Author

Thanks for your help. I have opened a PR that should fix your issue. It will ensure that the last ID is reset to None when there is an update showing now messages. This will en sure the event is re-triggered when a new message comes in that might have the same UID (e.g. 1)

Thanks for hanging in there to understand!

@dataworx22
Copy link

@talormanda - I've been scratching my head for days trying to resolve what I believe is the same/similar problem. My IMAP sensor checks all incoming mail for a specific sender but the sensor state as reported in developer tools does not update as expected, leading to intermittent notifications. Any idea when the fix will be rolled out?

@talormanda
Copy link
Author

@talormanda - I've been scratching my head for days trying to resolve what I believe is the same/similar problem. My IMAP sensor checks all incoming mail for a specific sender but the sensor state as reported in developer tools does not update as expected, leading to intermittent notifications. Any idea when the fix will be rolled out?

You would have to ask @jbouwh that.

@jbouwh
Copy link
Contributor

jbouwh commented May 22, 2023

The documentation shows an example on how to filter a specific sender. The only limitation is that you can only configure one sender. An other option is to grate a template sensor based on the custom event.

https://www.home-assistant.io/integrations/imap/#example---extracting-formatted-text-from-an-email-using-template-sensors

If there is another issue, feel free to open a new issue.

@dataworx22
Copy link

Thanks for your response Jan. My problem is that the sensor that was created when I updated to the IMAP integration does not accurately reflect the state of the desired field (in my case, I'm monitoring the Sender field). When I receive an email in the relevant Inbox, the IMAP sensor increments the number of UnSeen/UnRead mails but the sensor that deals with monitoring the sender field does not update accordingly, instead it remains on a sender adress of some days ago.

@jbouwh
Copy link
Contributor

jbouwh commented May 22, 2023

May be your email size is the issue: see #93138.
If this is the case the message is truncated.

@dataworx22
Copy link

I don't think so, considering the sensor is not looking at the body text of the email, only at the sender?

@jbouwh
Copy link
Contributor

jbouwh commented May 22, 2023

The event data can be filtered, but this is limited. If you need more advanced conditions you need to add them to your automation acting upon state changes of your template sensor.

@dataworx22
Copy link

The trouble is that the state of the template sensor is not changing reliably based on the search parameter ie Sender, I have no problem with the automation/notification side of things.

@jbouwh
Copy link
Contributor

jbouwh commented May 22, 2023

I suggest you open an issue to reflect you problem.

@dataworx22
Copy link

Thanks Jan, reason I'm posting here is because I suspect this is the same issue as per original poster. Should I open a new issue?

@jbouwh
Copy link
Contributor

jbouwh commented May 22, 2023

Yes, as this issue has to do with an empty mailbox not updating

@dataworx22
Copy link

Thanks very much for your time, I'll open an issue.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants