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
This commit is contained in:
Agent Zero
2026-07-17 22:50:02 +02:00
parent 60081c5262
commit c6364d40e6
3 changed files with 74 additions and 18 deletions
+1
View File
@@ -111,6 +111,7 @@ class Mail(Base, TenantMixin):
ForeignKey("mail_folders.id", ondelete="CASCADE"),
nullable=False,
)
imap_uid: Mapped[str | None] = mapped_column(String(20), nullable=True)
message_id: Mapped[str] = mapped_column(String(512), nullable=False)
thread_id: Mapped[str] = mapped_column(String(512), nullable=False, default="")
in_reply_to: Mapped[str | None] = mapped_column(String(512), nullable=True)