15 Commits
Author SHA1 Message Date
duffyduckandClaude Opus 4.7 1c30bffb5e add "reset all processed" button + endpoint
POST /api/filters/reset-all-processed drops and recreates the
processed_mails table — sekundenschnell auch bei Millionen Zeilen
via DROP+CREATE (same pattern as the fast clear-logs). Safe because
already-moved mails are no longer in the source folder, so a fresh
re-evaluation cannot re-move them, only pick up ones that were
skipped due to a rule bug (e.g. the has_attachment fix).

Button "Alle Regeln zurücksetzen" next to "Neue Regel" on the filter
list, with a confirmation dialog and result feedback.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-09-01 12:39:03 +02:00
duffyduckandClaude Opus 4.7 51ed9e4235 detect attachments without Content-Disposition: attachment header
The cps datensysteme rule (from cps-datensysteme.de + subject "Rechnung"
+ has_attachment true + date after) was failing on real invoices from
CPS ORMS. Their PDFs arrive without a Content-Disposition header — the
filename lives only on the Content-Type parameter — so _has_attachment
returned False and the rule never matched.

Extended the check to also count a part as an attachment when it has a
filename() and its content-type is neither text/* nor multipart/*.
That catches PDFs, Office and image attachments regardless of whether
the sender set Content-Disposition, without treating body parts as
attachments. Verified against four synthetic cases including the exact
CPS ORMS shape.

Same helper is now applied to non-multipart mails too, in case an entire
mail is a single attached file (rare but possible).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-09-01 12:32:48 +02:00
duffyduckandClaude Opus 4.7 a38b8ce8c1 scheduler: process newest UIDs first to prioritize fresh mail
The per-rule batch was sliced from all_uids in server order (oldest
UID first), so with a big backlog the scheduler chewed through years
of unmatched newsletters before reaching the current invoices the
user was actually waiting on. Sort new_uids descending by int (with a
plain reverse() fallback for non-numeric UIDs) so each poll picks the
newest 500 first. Old backlog still gets worked off in the background.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-09-01 12:04:12 +02:00
duffyduckandClaude Opus 4.7 e73d90747b fast log clear + robust API error handling
- fix: "Log leeren" without account filter used a plain DELETE over
  millions of rows. That held the sqlite write lock long enough that
  the scheduler's own log writes started failing with
  "database is locked", and the request itself eventually 500'd back
  as HTML "Internal Server Error" — which the frontend then tried to
  JSON.parse, producing the popup the user reported. Now uses
  DROP+CREATE for full clears (near-instant) and wal_checkpoint to
  reclaim space; per-account clear still uses a normal DELETE.
- Raise sqlite busy_timeout from 10s to 60s so a legitimately slow
  writer no longer starves smaller ones.
- retry-failed: single bulk DELETE with mail_uid IN (...) per account
  instead of one query per uid.
- Both endpoints now return proper HTTPException(500, ...) with detail
  instead of letting the exception bubble as plain text.
- Frontend: parseResponse() reads text first, then tries JSON. Both
  clearLogs() and retryFailed() surface the actual server message
  instead of crashing on non-JSON responses.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-09-01 11:52:26 +02:00
duffyduckandClaude Opus 4.7 e1f3231365 add release.sh: build + tag both version and latest, then push
Takes a version (e.g. 2.1), validates its format, runs docker build
once with both tags to skip a second build pass, then pushes both.
Warns on uncommitted changes but doesn't block.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-09-01 11:52:26 +02:00
duffyduckandClaude Opus 4.7 54183fdc3a robust charset decoding + retry-failed endpoint
- fix: fetch_mail crashed on MIME pseudo-encodings like 'unknown-8bit',
  'x-unknown', '8bit'. New _safe_decode helper maps those (and any
  LookupError from unknown codecs) to latin-1, which never fails on
  8-bit input. Used in _extract_body and _decode_header_value.
- Consequence of the crash: scheduler marked the affected UIDs as
  processed to avoid retry loops, so those mails never got sorted
  even after the underlying issue was fixable.
- feat: POST /api/filters/retry-failed drops the ProcessedMail markers
  for UIDs that appear in "Fehler beim Abrufen" error logs, so the
  next poll re-evaluates them. Reachable via a button in the log UI
  ("Fehlgeschlagene neu einlesen"), optionally scoped per account.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-09-01 11:32:54 +02:00
duffyduckandClaude Opus 4.7 e4669cfccd add live search to filter rules list
Substring search across rule name, source folder, condition values
and action parameters. Filters the table client-side as the user
types and shows a match counter (e.g. "3 / 12").

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-31 10:51:32 +02:00
duffyduckandClaude Opus 4.7 202920b9ef auto-assign filter priority (max+10) on create
New filter rules no longer default to priority 100. Server picks
max(priority)+10 per account when client sends priority=None (or 10
if the account has no rules yet), and the UI pre-fills the input
with the next value instead of a fixed 100. Avoids ambiguous ordering
when multiple rules end up with the same priority.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-31 10:46:52 +02:00
duffyduckandClaude Opus 4.7 b77b192b56 fix UI 500 + slow backup with millions of processed_mails
- fix: Starlette 1.0 changed TemplateResponse signature — request is now
  the first positional argument, not nested inside the context dict.
  All HTML routes returned 500 (unhashable dict in jinja2 template cache)
  after the image rebuild picked up the new starlette version.
- fix: processed_mails (1.7M rows in production: 1 account × 12 rules ×
  141k inbox mails) made backup export hit 558 MB / 90s. Moved to opt-in
  checkbox in the UI alongside the logs option, default off.
- yield_per for streaming the processed_mails query when included.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 20:37:32 +02:00
duffyduckandClaude Opus 4.7 7e7ec67e58 safe move + sqlite WAL + log indexes + backup with logs
- fix: imap folder names with spaces (RFC3501 quoting in move/create/select)
- fix: move only deletes source after COPY + Message-ID verification in target
- fix: backup endpoint hung on sqlite write locks — enable WAL + busy_timeout
- perf: indexes on filter_logs(created_at, level, account_id+created_at) for
  fast log queries on millions of rows
- feat: optional "logs mit sichern" checkbox in backup export, restore on import
- UI: backup download uses fetch+blob with error display instead of location.href

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-18 19:54:32 +02:00
duffyduck 66b32ded36 fixed, scheduler, added search to log, added advanced search 2026-04-05 18:55:09 +02:00
duffyduck 076733fb53 added messgage bundel not all at one, added sepearte memory at every filter 2026-03-19 16:05:25 +01:00
duffyduck d148248682 addes folder backup attachments logging 2026-03-19 15:31:36 +01:00
Stefan Hacker 61c4384111 Initial commit: IMAP Mail Filter Service 2026-03-19 13:02:44 +01:00
Stefan Hacker 44fb27801d Add .gitignore 2026-03-19 13:02:44 +01:00