fix: implement server-side folder filtering using IMAP LIST patterns

Replace client-side wildcard filtering with IMAP LIST pattern matching
for improved efficiency and accuracy. This fixes the issue where patterns
like "Work*" were not matching folders like "Work/Projects".

Key improvements:
- Use IMAP LIST with patterns for server-side filtering
- Remove dependency on doublestar library
- Add ListFilteredMailboxes() method with proper IMAP pattern support
- Remove obsolete ShouldProcessMailbox() client-side filtering
- Significantly reduce network traffic by filtering at server

This ensures the Go implementation correctly processes folder patterns
and achieves feature parity with the Rust implementation.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2025-08-03 14:26:03 +02:00
commit 84faf501f1
2 changed files with 83 additions and 52 deletions

View file

@ -66,12 +66,13 @@ func processImapSource(source *config.MailSource, couchClient *couch.Client, dbN
fmt.Println(" IMAP connection successful.")
mailboxes, err := imapClient.ListMailboxes()
// Use IMAP LIST with patterns for server-side filtering
mailboxes, err := imapClient.ListFilteredMailboxes(&source.FolderFilter)
if err != nil {
return fmt.Errorf("failed to list mailboxes: %w", err)
return fmt.Errorf("failed to list filtered mailboxes: %w", err)
}
fmt.Printf(" Found %d mailboxes.\n", len(mailboxes))
fmt.Printf(" Found %d matching mailboxes after filtering.\n", len(mailboxes))
// Parse the since date from config if provided (fallback for first sync)
var configSinceDate *time.Time
@ -87,14 +88,8 @@ func processImapSource(source *config.MailSource, couchClient *couch.Client, dbN
totalMessages := 0
totalStored := 0
// Process each mailbox
// Process each mailbox (already filtered by IMAP LIST)
for _, mailbox := range mailboxes {
// Check if this mailbox should be processed based on filters
if !imapClient.ShouldProcessMailbox(mailbox, &source.FolderFilter) {
fmt.Printf(" Skipping mailbox: %s (filtered)\n", mailbox)
continue
}
fmt.Printf(" Processing mailbox: %s (mode: %s)\n", mailbox, source.Mode)
// Get sync metadata to determine incremental sync date