Skip to content

Add Fastmail polling support for real-time email processing#2

Open
marcodejongh wants to merge 2 commits intoclaude/add-fastmail-support-bu4nMfrom
claude/fastmail-polling-support
Open

Add Fastmail polling support for real-time email processing#2
marcodejongh wants to merge 2 commits intoclaude/add-fastmail-support-bu4nMfrom
claude/fastmail-polling-support

Conversation

@marcodejongh
Copy link
Owner

Summary

  • Implements polling-based email sync for Fastmail since webhooks aren't supported for third-party apps
  • Adds JMAP Email/changes API support for efficient incremental sync
  • Creates /api/fastmail/poll cron endpoint for background polling (every 5 minutes)
  • Adds "Check for new mail" button in settings for manual sync
  • Updates watch-manager to handle Fastmail gracefully (skip webhook setup)

Background

Fastmail doesn't support push notifications (webhooks/EventSource) for third-party applications. This means:

  • Gmail-style real-time webhooks are not available
  • Server-side filters (Sieve) have no programmatic API

This PR adds polling as an alternative to achieve near-real-time email processing.

Changes

New Files

  • utils/fastmail/poll-sync.ts - Core polling logic
  • app/api/fastmail/poll/route.ts - Cron endpoint
  • utils/actions/fastmail-sync.ts - Server action for manual sync
  • components/FastmailSyncButton.tsx - UI button component
  • assistant/settings/FastmailSyncSetting.tsx - Settings card

Modified Files

  • utils/email/fastmail.ts - Added getEmailChanges() method
  • utils/email/watch-manager.ts - Handle Fastmail case
  • utils/email/provider-types.ts - Added helper functions
  • prisma/schema.prisma - Added lastPolledAt field

Test plan

  • Create a Fastmail account and link it
  • Verify the sync button appears in settings
  • Click sync button and verify it processes new emails
  • Test cron endpoint manually: curl -H "Authorization: Bearer $CRON_SECRET" /api/fastmail/poll
  • Verify rules execute on synced emails

🤖 Generated with Claude Code

Since Fastmail doesn't support webhooks for third-party apps, this PR
implements polling-based email sync as an alternative:

Features:
- Add JMAP Email/changes API support via getEmailChanges() method
- Create /api/fastmail/poll cron endpoint for background polling
- Add "Check for new mail" button for manual sync in settings
- Update watch-manager to handle Fastmail accounts gracefully
- Add lastPolledAt field to track polling state

Technical details:
- Uses JMAP state tokens (via lastSyncedHistoryId) for efficient sync
- Processes new emails through existing rule engine
- Skips recently polled accounts (<2 min) during cron
- Returns far-future expiration to prevent watch-manager errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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