Gmail IMAP sensor stops working after a period of time

I have updated to 2023.5.2 and migrated my gmail imap sensor that turns on lights when the alarm is disarmed and turns off lights when it is armed:

template:
  - trigger:
      - platform: event      
        event_type: "imap_content"
        id: "custom_event"
        event_data:
          sender: "[email protected]"
    sensor:
      - name: Alarm Status
        state: >
          {% if 'Armed Away' in trigger.event.data["subject"] %}
            armed_away
          {% elif 'Armed Stay' in trigger.event.data["subject"] %}
            armed_stay
          {% elif 'Disarmed' in trigger.event.data["subject"] %}
            disarmed
          {% endif %}

Problem is that is seems to stop working after a period of time. So does the generic imap sensor I set up just to see all email traffic to help debug.
When I restart Home Assistant it starts working again. I can’t see anything in the log at the time to tell me what’s gone wrong. Any ideas?

Happened again this morning. Had to restart HA. There’s nothing in the log.
Probably coincidence but both times it has stopped working with an email from the local weather blog.