Commit Graph

68 Commits

Author SHA1 Message Date
Agent Zero fb92acb52b fix: bidirectional sync — check sync queue before restoring deleted mails
- 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
2026-07-20 14:35:36 +02:00
Agent Zero 452828babe fix: never restore deleted mails during sync — deleted means deleted
- 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
2026-07-20 14:26:07 +02:00
Agent Zero 4acebe55e5 fix: stop cross-folder message_id dedup — mails were being moved between folders
- 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
2026-07-20 14:03:19 +02:00
Agent Zero 1a2f7f3ab6 fix: stop sync from moving Trash mails back to Inbox
- 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
2026-07-20 13:56:30 +02:00
Agent Zero 7631698215 fix: restore deleted_at mails when still on IMAP server — sync was permanently hiding mails
- 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
2026-07-20 13:46:48 +02:00
Agent Zero 04e0c60222 fix: add deleted_at column to mail_sync_queue — process_sync_queue was crashing
- 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
2026-07-20 13:42:30 +02:00
Agent Zero 11c2a0c9af fix: deleted mails showing in inbox — set deleted_at on move to Trash, show in Trash folder
- 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
2026-07-20 13:26:39 +02:00
Agent Zero b68accb9a1 fix: IMAP sync overhaul - move to Trash, fix func import, fix count queries
- 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
2026-07-20 13:17:07 +02:00
Agent Zero 5ded6f7d0b fix: dedup by message_id in imap_sync_folder — stop deleted mails reappearing from Trash
- 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
2026-07-20 12:59:19 +02:00
Agent Zero 478ea877f9 fix: stop restoring soft-deleted mails during sync — they stay deleted
- 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
2026-07-20 12:40:27 +02:00
Agent Zero 61ab481349 fix: incremental IMAP sync - only fetch new UIDs since last known, like real mail clients
- 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
2026-07-20 12:12:53 +02:00
Agent Zero 3313047577 feat: live IMAP sync on folder select + 60s auto-sync interval
- 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()
2026-07-20 12:01:16 +02:00
Agent Zero c24a86bc90 fix: IMAP sync - use imap_uid, add sync queue with retry, restore deleted on sync, upload sent mails
- 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
2026-07-20 11:31:17 +02:00
Agent Zero 9143346824 fix: add flag_type migration to plugin manifest + bump version to trigger migration run 2026-07-20 10:44:52 +02:00
Agent Zero 9da04057b9 feat: mail list font size, remove Termin toolbar, rename Flagge to Markierung with symbol picker
- 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
2026-07-20 10:39:16 +02:00
Agent Zero 9063093a5a feat: compact mail folder tree + right-click Ordner leeren
- 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
2026-07-20 09:25:43 +02:00
Agent Zero c670846cbd Update unified search providers for unified contacts model (company queries contacts with type=company) 2026-07-19 21:32:24 +02:00
Agent Zero cf75680583 Unified contacts model: Rentman-style type field (company/person), inline addresses, ContactPerson 1:N, all Rentman fields except rental-specific 2026-07-19 21:12:49 +02:00
Agent Zero dc24c37c19 feat: use OpenRouter for embeddings with text-embedding-3-small (768 dims)
- 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
2026-07-19 19:21:49 +02:00
Agent Zero 5db7364071 fix: increase max_tokens for LLM suggestions to prevent truncated JSON 2026-07-19 02:32:39 +02:00
Agent Zero 5c3fc027bc fix: strip markdown code fences from LLM responses before json.loads
- glm-5.2 returns JSON wrapped in ```json ... ``` code fences
- Added fence stripping in services.py, query_understanding.py, jobs.py
2026-07-19 02:30:07 +02:00
Agent Zero 4a43745b50 fix: unified_search + ai_proactive get API key from DB, fix model names for Ollama Cloud
- 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
2026-07-19 02:22:25 +02:00
Agent Zero ef4f0cc494 fix: use provider_type for model prefix and base_url for Ollama Cloud
- _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
2026-07-19 01:51:14 +02:00
Agent Zero 7f8344bc24 fix: get LLM API key from DB instead of env var
- 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
2026-07-19 01:36:16 +02:00
Agent Zero b1153e0c54 fix: add updated_at columns to ai_proactive migration
- ai_proactive_suggestions: add updated_at TIMESTAMPTZ
- ai_proactive_context_log: add updated_at TIMESTAMPTZ

TenantMixin inherits TimestampMixin which expects both created_at and updated_at.
Missing updated_at caused 500 errors on /ai-proactive/context POST.
2026-07-18 18:22:16 +02:00
Agent Zero df82796023 fix: add deleted_at columns to ai_proactive migration
- ai_proactive_suggestions: add deleted_at TIMESTAMPTZ
- ai_proactive_context_log: add deleted_at TIMESTAMPTZ
- ai_proactive_settings: add deleted_at TIMESTAMPTZ

ORM models expect deleted_at for soft-delete support.
2026-07-18 16:18:45 +02:00
Agent Zero 8cebb4f4e9 feat: unified_search + ai_proactive plugins with Ollama Cloud DeepSeek V4
- unified_search: Hybride Suche (PostgreSQL FTS + pgvector + RRF Fusion)
  - 5 Search Providers (Contact, Company, Mail, File, Event)
  - KI Query Understanding (Fuzzy, Facetten via LiteLLM)
  - DMS Text-Extraction (PDF, DOCX, XLSX, PPTX)
  - Embedding Pipeline (ollama/nomic-embed-text, 768 Dim)
  - Background Jobs für Indexierung
  - Plugin-basierte Provider Registry

- ai_proactive: Proaktiver KI-Agent
  - Context-Tracking (Frontend → Backend → Event Bus)
  - Proactive Engine mit LLM Suggestion-Generierung
  - SSE Real-time Push an Frontend
  - 6 AI Tools für Tool Registry
  - Rate-Limiting + User Settings
  - Deep Analysis Background Jobs

- Frontend Integration:
  - useAIContext Hook, SuggestionSidebar, SuggestionBadge
  - ProactiveAISettings Page, Search API Client
  - Globale Suche auf neue API umgestellt

- Tests: test_unified_search.py + test_ai_proactive.py (alle bestanden)
- Config: Ollama Cloud DeepSeek V4 als Default, konfigurierbar
- Dependencies: PyMuPDF, python-docx, python-pptx, pgvector
- Bugfixes: notification type_key length, migration IF NOT EXISTS
2026-07-18 11:21:51 +02:00
Agent Zero db433e81f1 feat: mail UI improvements - folder mapping, display name, resize perf, list header
- Add configurable folder mapping (sent/drafts/spam/trash) per account
- Migration 0005_folder_mapping.sql with 4 new columns on mail_accounts
- Backend: send_mail uses account.sent_folder_imap_name if set
- Backend: _build_folder_hierarchy respects folder_mapping for is_standard
- Frontend: MailSettings shows folder mapping editor per account
- Frontend: MailSettings allows editing display_name for existing accounts
- Frontend: MailFolderTree shows display_name || email, removes MailIcon
- Frontend: ResizablePanel isDragging state with contain:strict + pointer-events:none
- Frontend: MailList merges select-all and sort controls into one line
2026-07-17 23:17:52 +02:00
Agent Zero 04c419402b fix: increase MAX_EMAILS_PER_FOLDER to 2000 for complete sync 2026-07-17 23:02:53 +02:00
Agent Zero 153e7f0d23 fix: increase MAX_EMAILS_PER_FOLDER from 50 to 500 for full sync 2026-07-17 23:00:22 +02:00
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
Agent Zero 3fc4dcdb96 fix: add folder_id and sort_order to AIChatSession model, fix UUID conversion in routes, add migration 0003 2026-07-17 21:20:49 +02:00
Agent Zero 70b8a66fd4 feat: attachment context for LLM, markdown rendering, mobile layout with back arrow 2026-07-17 13:45:21 +02:00
Agent Zero 9a29206190 feat: chat folders, attachments, treeview backend - migration, models, routes 2026-07-17 09:15:39 +02:00
Agent Zero 50650f5b17 fix: always add provider prefix to litellm model string 2026-07-17 01:48:08 +02:00
Agent Zero 561d1919f5 fix: add deleted_at columns to AI Assistant migration SQL 2026-07-17 01:08:13 +02:00
Agent Zero 8255704ff9 fix: add missing AIPreset import in routes.py 2026-07-17 01:06:08 +02:00
Agent Zero 26feadf179 AI Assistant plugin: backend with LiteLLM, agents, tools, streaming chat 2026-07-17 00:45:24 +02:00
Agent Zero 2278ec2722 fix(mail): robust MIME filename decoding with fallback for attachments
- 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
2026-07-16 23:30:13 +02:00
Agent Zero 0c310c5028 fix(mail): decode MIME-encoded attachment filenames during sync
- 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
2026-07-16 23:23:27 +02:00
Agent Zero 881f4817be fix(mail): save attachments for existing emails during sync
- 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
2026-07-16 23:08:37 +02:00
Agent Zero 2a80aeb0af fix(mail): sync Object error, MIME subject decoding, sticky compact pagination
- 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
2026-07-16 09:40:59 +02:00
Agent Zero a4560344c9 feat: phase 5 - mail plugin RBAC integration with delegate access levels (read/write/delete/full) 2026-07-16 00:34:36 +02:00
Agent Zero beaca24480 feat: phase 3 - field-level permissions with plugin field definitions, service-layer filtering, 20 core field definitions 2026-07-15 23:02:30 +02:00
Agent Zero b0e987f790 feat: notification preferences system with plugin registry
- Add NotificationType and NotificationPreference models
- Add get_notification_types() to BasePlugin for plugin registration
- Add sync_notification_types() to PluginRegistry
- Update create_notification() to check user preferences (returns Notification|None)
- Add API endpoints: GET /types, GET /preferences, PATCH /preferences/{type_key}
- Add NotificationPreferenceUpdate schema
- Mail plugin registers 10 notification types with metadata
- Add Alembic migration 0017 for new tables + seed data
- Frontend: SettingsNotifications page with toggle switches
- Frontend: Settings tab, route, hooks for notification preferences
- i18n: notification settings keys (de/en)
2026-07-15 21:00:32 +02:00
Agent Zero c4d0ec6f7f feat: mail notification integration - 10 notification types
- mail_new: new mails during sync (max 10, then summary)
- mail_error: IMAP connection failure
- mail_auth: IMAP login failure
- mail_quota: mailbox quota >80% / >95% critical
- mail_sync_error: general sync failure per account
- mail_sent: mail sent confirmation
- mail_send_error: SMTP send failure
- mail_draft: draft saved confirmation
- mail_account: account inactive warning
- mail_folder: folder created/deleted confirmation
- All notifications non-critical (try/except wrapped)
- Import create_notification from app.core.notifications
2026-07-15 20:41:57 +02:00
Agent Zero f1a12092a0 feat: mail phase 4 - IMAP folder create/delete + auto-sync
- Add imap_create_folder() and imap_delete_folder() service functions
- Call IMAP CREATE/DELETE in folder create/delete endpoints
- Add auto_sync_all_accounts() background task (every 5 min)
- Start auto-sync loop on plugin activation via asyncio.create_task
- Frontend: working sync button with isSyncing state and toast feedback
- i18n: syncSuccess, syncFailed, syncing, autoSyncEnabled keys (de/en)
2026-07-15 20:28:11 +02:00
Agent Zero 4e100e9d33 feat: mail phase 3 - sorting (date/from/subject, asc/desc)
- Add sort_by and sort_order query params to list_mails endpoint
- Add deleted_at IS NULL filter to exclude soft-deleted mails
- Frontend: sort state in Mail.tsx, sort header bar in MailList
- Sort dropdown (Datum/Absender/Betreff) + asc/desc toggle
- fetchMails API accepts optional sortBy/sortOrder params
- i18n: 6 new sort keys (de/en)
2026-07-15 20:17:27 +02:00
Agent Zero ed1eec87dc feat: mail phase 2 - delete, move, drafts
- Add deleted_at field to Mail/MailAccount/MailFolder models
- Add DELETE /{mail_id} endpoint (soft-delete + IMAP EXPUNGE)
- Add POST /{mail_id}/move endpoint (IMAP UID MOVE + folder_id update)
- Add POST /drafts and PUT /drafts/{id} endpoints (save/edit drafts)
- Add imap_delete_mail() and imap_move_mail() service functions
- Add save_draft() and update_draft() service functions
- Frontend: deleteMail, moveMail, saveDraft, updateDraft API functions
- ComposeModal: draft mode with Save Draft button
- MailDetail: delete/move buttons, edit-draft for drafts
- Mail.tsx: bulk delete/move, move dropdown, draft handlers
- i18n: 13 new keys (de/en)
2026-07-15 19:44:46 +02:00
Agent Zero df83cee10c feat: mail phase 1 - HTML iframe display, bulk read/unread, IMAP flag sync
- Fix FlagUpdatePayload field names to match backend schema (is_seen/is_flagged)
- Replace dangerouslySetInnerHTML with sandboxed iframe (srcDoc, sandbox="")
- Add bulk mark read/unread with checkbox selection in MailList
- Add floating bulk action bar in Mail.tsx
- Add imap_sync_mail_flags() to push Seen/Flagged flags to IMAP server
- Call IMAP flag sync in PATCH /flags endpoint
- Add i18n keys for bulk actions (de/en)
2026-07-15 19:26:37 +02:00