- If mail has deleted_at and is still on IMAP server:
- Check sync queue for pending delete operation
- If pending delete exists: our IMAP delete failed, keep deleted, retry via queue
- If no pending delete: another program restored the mail, restore in DB
- This enables true bidirectional sync like Thunderbird/Outlook
- Sync was restoring deleted_at mails when found on IMAP server
- This caused deleted mails to reappear in inbox on every sync
- Now deleted mails are always skipped during sync, never restored
- IMAP delete is retried via sync queue
- message_id dedup was searching across ALL folders
- A mail in Trash with same message_id as one in INBOX was found and moved to INBOX
- Now message_id dedup only searches within the SAME folder
- This matches how real mail clients work: same message_id in different folders = separate copies
- When mail is moved to Trash in DB (folder_id=Trash, deleted_at set) but IMAP MOVE fails,
the mail stays in INBOX on the IMAP server
- Previously sync restored deleted_at and moved folder_id back to INBOX
- Now sync only restores if mail is in the SAME folder in DB and IMAP
- If mail is in Trash in DB but INBOX on IMAP, skip it — sync queue will retry the MOVE
- When IMAP delete fails, deleted_at stays set but mail remains on IMAP server
- Sync was skipping deleted_at mails, so they stayed permanently hidden
- Now sync restores deleted_at=None when mail is found on IMAP server
- This means: if IMAP delete fails, mail reappears in LeoCRM on next sync
- Only truly deleted mails (removed from IMAP server) stay hidden
- MailSyncQueue inherits TenantMixin which includes SoftDeleteMixin (deleted_at)
- Migration 0007 did not create this column
- process_sync_queue crashed on every auto-sync attempt
- Add migration 0008 to add deleted_at column
- Bump plugin version to 1.3.0
- delete_mail: set deleted_at when moving to Trash (not just folder_id)
- empty_folder: same — set deleted_at when moving to Trash
- list_mails: show soft-deleted mails when viewing Trash folder
- This prevents sync from moving deleted mails back to inbox
- Trash folder shows deleted_at mails, all other folders hide them
- Fix missing func import (imap_sync_folder was crashing silently)
- imap_delete_mail now moves to Trash folder instead of permanent delete
- Add permanent parameter: permanent=True for Trash->delete, False for Inbox->Trash
- delete_mail route: move to Trash if not in Trash, permanent delete if in Trash
- empty_folder: move to Trash or permanent delete if already in Trash
- Add Papierkorb/Trash folder to create_mail_account
- Fix not Mail.is_seen -> Mail.is_seen.is_(False) (SQLAlchemy bug)
- Fix select(text("COUNT(*)")) -> select(func.count()).select_from(Mail)
- process_sync_queue reads permanent flag from payload
- imap_sync_folder now checks message_id in addition to (folder_id, imap_uid)
- If mail was moved to Trash by IMAP server (new UID, same message_id), it is recognized
- Soft-deleted mails with matching message_id are skipped, not re-created
- Prevents deleted mails from reappearing when IMAP server moves them to Trash
- Removed restore logic from imap_sync_account and imap_sync_folder
- Soft-deleted mails are now skipped during sync (not touched, not restored)
- This prevents deleted mails from reappearing when they are found on IMAP
- The sync queue handles retrying failed IMAP deletes
- imap_sync_folder now searches only UID > max_known_uid instead of ALL
- First sync gets last 50, subsequent syncs only get new mails
- UI loads cached mails immediately from DB, sync runs in background
- Folder counts updated after sync
- New imap_sync_folder function: syncs single folder quickly for live use
- New POST /mail/folders/{folder_id}/sync route
- Frontend: syncFolder API + called on every folder selection
- Auto-sync interval reduced from 300s to 60s
- Sent mail IMAP APPEND already uploads full body via msg.as_bytes()
- imap_delete_mail: use stored imap_uid instead of Message-ID search, raise on failure
- imap_move_mail: same imap_uid fix, raise on failure
- New MailSyncQueue model + migration 0007 for pending IMAP operations
- delete_mail route: queues failed IMAP delete for retry
- move_mail route: queues failed IMAP move for retry
- process_sync_queue: retries pending delete/move operations in auto-sync loop
- Auto-sync loop: processes sync queue before pulling new mails
- Restore soft-deleted mails if they still exist on IMAP server during sync
- Upload sent mails to IMAP Sent folder via APPEND after SMTP send
- Plugin version bumped to 1.2.0
- Mail list: title and subject font text-xs -> text-sm
- Remove Termin (create-event) toolbar button
- Rename Flagge -> Markierung with select dropdown (star, flag, bookmark, important, question)
- Backend: add flag_type column to Mail model + migration 0006
- Backend: flag_type in MailFlagsUpdate schema, update_flags route, mail_to_response
- Frontend: flag_type in Mail interface, FlagUpdatePayload, MailList symbol display
- MailFolderTree: compact styling matching AI assistant SessionList (py-1, text-sm, depth*12+8 padding, no space-y)
- Added right-click context menu on folders with "Ordner leeren" entry
- Backend: POST /mail/folders/{folder_id}/empty soft-deletes all mails in folder
- Frontend API: emptyFolder() function added to mail.ts
- Mail.tsx: onFolderEmptied callback reloads mails and folders
- Ollama Cloud has no embedding endpoint, OpenRouter does
- text-embedding-3-small with dimensions=768 matches DB vector(768) column
- API_KEY_OPENROUTER env var is primary, DB provider is fallback
- Added dimensions parameter for text-embedding-3 models
- query_understanding.py: get API key/base_url/provider_type from ai_providers DB
- embedding.py: get API key from DB, pass db+tenant_id through call chain
- routes.py: pass db+tenant_id to llm_analyze_query and llm_aggregate_results
- search_engine.py: pass db+tenant_id to generate_embedding
- unified_search/jobs.py: pass db+tenant_id to generate_embedding
- Fix all default model names: ollama/deepseek-v4 -> ollama/deepseek-v4-flash
- Ollama Cloud has no embedding endpoint; embedding calls fail gracefully
- _get_llm_api_key now returns provider_type
- Model string built with provider_type prefix (openai/deepseek-v4 instead of ollama/deepseek-v4)
- api_base set from provider.base_url (https://ollama.com/v1)
- Fixes: litellm tried localhost:11434 instead of Ollama Cloud
- ai_proactive now reads API key from ai_providers table (like ai_assistant)
- Falls back to API_KEY_OLLAMA_CLOUD env var if no provider found
- Fixes: proactive engine could not generate suggestions because API key was empty
- 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
- Add _decode_mime_filename() helper with Q-encoding fallback decoder
- Use helper for both new and existing email attachment saving
- Handles edge cases where email.header.decode_header fails on partially processed filenames
- Decode =?utf-8?q?...?= filenames before sanitizing for both new and existing emails
- Prevents filenames like __utf-8_q_Wire_236095209372_2Epdf_2Ehtml__
- Uses email.header.decode_header + make_header for proper decoding
- IMAP sync now saves attachments for existing emails that have has_attachments=true
but no attachment records in the database (retroactive attachment saving)
- Replace silent exception catching with logger.warning for attachment save failures
- Add logging module import and logger instance
- This fixes the issue where 62 emails had has_attachments=true but 0 attachment records
- Fix sync error: backend returns {synced, error?} not {success, synced_count}; frontend now checks error field
- Decode MIME encoded-words (=?UTF-8?Q?...?=) in backend during IMAP sync for subject/from/to/cc headers
- Add frontend decodeMimeHeader() utility for already-stored encoded subjects (MailList + MailDetail)
- Make pagination sticky at bottom of mail list (flex-col h-full, ul scrolls, pagination flex-shrink-0)
- Make pagination compact: smaller padding (px-1.5 py-0.5), text-xs, smaller icons, tighter spacing