* Add .claude to gitignore
* Add imap_session module for centralized OAuth2 refresh
Create new imap_session.py module that combines imap_common and
imap_oauth2 for unified session management:
- ensure_connection(): Refreshes OAuth2 token and ensures connection health
- ensure_folder_session(): Ensures connection AND folder selection
Updated backup, migrate, and restore scripts to use the new module,
simplifying the proactive token refresh pattern in process_batch
functions.
* Move is_token_expired_error to imap_oauth2 module
Relocates the OAuth2 token expiration detection function to the oauth2-specific module where it logically belongs.
* Add retry logic for auth errors during email processing
Extract single-UID processing into dedicated functions with retry capability
for recoverable authentication failures. Broadens auth error detection beyond
token expiration to include session loss and authentication failures.
* Cache Microsoft tenant discovery results
Avoids repeated OpenID Connect discovery requests for the same email domain
during OAuth2 authentication flows. Normalizes domain to lowercase for
consistent cache keys.
* Add tests for is_token_expired_error and is_auth_error
Covers token expiration, session invalidation, and authentication failure
detection with case-insensitive matching verification. Ensures non-auth
errors like connection and timeout issues are correctly excluded.
* Add tests for imap_session module
Covers ensure_connection and ensure_folder_session functions including
OAuth2 token refresh, folder selection, and error handling scenarios.
Verifies connection change detection triggers folder re-selection.
* Add tests for auth error re-raising in get_message_ids_in_folder
Verifies that authentication errors are propagated to callers for
reconnection handling while non-auth errors return empty results.
Clarifies test names to distinguish error handling behaviors.