Skip to content

Add IMAP IDLE support (RFC 2177)#218

Open
tyommik wants to merge 1 commit into
karastojko:masterfrom
tyommik:imap_idle
Open

Add IMAP IDLE support (RFC 2177)#218
tyommik wants to merge 1 commit into
karastojko:masterfrom
tyommik:imap_idle

Conversation

@tyommik
Copy link
Copy Markdown

@tyommik tyommik commented Feb 19, 2026

Implement IMAP IDLE command for real-time mailbox notifications, allowing clients to receive immediate push updates about new, deleted, and changed messages without polling. Changes:
include/mailio/imap.hpp:

  • Add idle_notification_type_t enum (EXISTS, EXPUNGE, FETCH)
  • Add idle_response_t struct for parsed server notifications
  • Add capability() / has_capability() methods for server capability discovery
  • Add idle() / idle_done() method declarations with private state members

src/imap.cpp:

  • Implement capability() — fetch and cache CAPABILITY response
  • Implement has_capability() — check for specific capability string
  • Implement idle() — enter IDLE mode, parse untagged notifications (EXISTS, EXPUNGE, FETCH), handle configurable timeout (default 29 min per RFC, recommended ~10 min for Gmail)
  • Implement idle_done() — send DONE to terminate IDLE; safe to call from another thread

examples/imap_idle.cpp:

  • Add usage example demonstrating IDLE connection, notification handling, and graceful shutdown

Protocol details:

  • Command sequence: tag IDLE → + continuation → untagged notifications → DONE → tag OK
  • Requires server IDLE capability advertisement
  • Must be in Selected mailbox state
  • Thread-safe design: idle_done() can be called from a separate thread to interrupt idle()

Implement IMAP IDLE command for real-time mailbox notifications, allowing clients to receive immediate push updates about new, deleted, and changed messages without polling.
Changes:
include/mailio/imap.hpp:

- Add idle_notification_type_t enum (EXISTS, EXPUNGE, FETCH)
- Add idle_response_t struct for parsed server notifications
- Add capability() / has_capability() methods for server capability discovery
- Add idle() / idle_done() method declarations with private state members

src/imap.cpp:

- Implement capability() — fetch and cache CAPABILITY response
- Implement has_capability() — check for specific capability string
- Implement idle() — enter IDLE mode, parse untagged notifications (EXISTS, EXPUNGE, FETCH), handle configurable timeout (default 29 min per RFC, recommended ~10 min for Gmail)
- Implement idle_done() — send DONE to terminate IDLE; safe to call from another thread

examples/imap_idle.cpp:

- Add usage example demonstrating IDLE connection, notification handling, and graceful shutdown

Protocol details:

- Command sequence: tag IDLE → + continuation → untagged notifications → DONE → tag OK
- Requires server IDLE capability advertisement
- Must be in Selected mailbox state
- Thread-safe design: idle_done() can be called from a separate thread to interrupt idle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant