Files
leocrm/app/plugins/builtins/mail/migrations/0004_imap_uid.sql
T
Agent Zero c6364d40e6 fix: mail sync duplicates, sent folder, delimiter detection, folder move tracking
- Add imap_uid column + unique index for proper deduplication
- Use deterministic message_id for emails without Message-ID header
- Dedup by (account_id, folder_id, imap_uid) first, message_id fallback
- Track folder moves: update folder_id when email appears in different folder
- Fix Sent folder lookup: check Sent/INBOX.Sent/Sent Items/Sent Mail + ILIKE
- Detect IMAP delimiter from LIST response instead of hardcoding dot
- Use detected delimiter in stale folder name migration
- Migration 0004_imap_uid.sql with imap_uid column and unique index
2026-07-17 22:50:02 +02:00

6 lines
391 B
SQL

-- Add imap_uid column to mails table for proper deduplication
ALTER TABLE mails ADD COLUMN IF NOT EXISTS imap_uid VARCHAR(20);
CREATE INDEX IF NOT EXISTS ix_mails_imap_uid ON mails(account_id, imap_uid);
-- Unique constraint to prevent duplicates per folder
CREATE UNIQUE INDEX IF NOT EXISTS uq_mails_account_folder_uid ON mails(account_id, folder_id, imap_uid) WHERE imap_uid IS NOT NULL;