fix: reset email poll state on process_unread_days config change

linuztx committed Mar 16, 2026 at 23:54 UTC 1d58eda8baa2664f9eacc4afba2b3d2842d61712
1 file changed +7 -8
plugins/_email_integration/extensions/python/job_loop/_10_email_poll.py
+7 -8
@@ -56,7 +56,7 @@ async def _handler_poll_loop(handler_name: str) -> None:
56 _state_lock,
57 )
58
59 - first_poll = True
59 + last_unread_days = 0
60
61 while True:
62 config = plugins.get_plugin_config(PLUGIN_NAME) or {}
@@ -71,13 +71,12 @@ async def _handler_poll_loop(handler_name: str) -> None:
71 try:
72 async with _state_lock:
73 state = _load_state()
74 - # On first poll after startup, reset state so the first-run
75 - # path processes recent unread emails via date-based search.
76 - # Subsequent polls use normal UID tracking.
77 - if first_poll:
78 - if int(handler_cfg.get("process_unread_days", 0)) > 0:
79 - state.pop(handler_name, None)
80 - first_poll = False
74 + # Reset state when process_unread_days is enabled or changed
75 + # so the first-run path processes recent unread via date search.
76 + unread_days = int(handler_cfg.get("process_unread_days", 0))
77 + if unread_days > 0 and unread_days != last_unread_days:
78 + state.pop(handler_name, None)
79 + last_unread_days = unread_days
80 await _poll_single_handler(handler_cfg, state)
81 _save_state(state)
82 except Exception as e: