feat(PROJ-38): rethread — rückwirkendes Mail-Threading
This commit is contained in:
@@ -285,6 +285,7 @@ Commands:
|
||||
export E-Mails exportieren (EML, MBOX)
|
||||
reindex Index neu aufbauen (alle oder pro Mandant)
|
||||
recompress Bestehende Mails nachträglich gzip-komprimieren
|
||||
rethread Thread-IDs rückwirkend aus In-Reply-To/References befüllen
|
||||
version Version anzeigen
|
||||
help Diese Hilfe anzeigen
|
||||
|
||||
@@ -327,5 +328,9 @@ archivmail reindex [flags]
|
||||
archivmail recompress [flags]
|
||||
--config Pfad zur Konfigurationsdatei (Standard: /etc/archivmail/config.yml)
|
||||
--dry-run Simulation: zeigt wie viel gespart würde, ohne Dateien zu ändern
|
||||
|
||||
archivmail rethread [flags]
|
||||
--config Pfad zur Konfigurationsdatei (Standard: /etc/archivmail/config.yml)
|
||||
--dry-run Simulation: zeigt wie viele Mails gethreaded würden, ohne DB zu ändern
|
||||
`, AppVersion)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/archivmail/config"
|
||||
"github.com/archivmail/internal/storage"
|
||||
)
|
||||
|
||||
// runRethread walks all emails without thread_id and sets thread relationships
|
||||
// by parsing In-Reply-To / References headers.
|
||||
//
|
||||
// Usage: archivmail rethread [--config path] [--dry-run]
|
||||
func runRethread(args []string) {
|
||||
fset := flag.NewFlagSet("rethread", flag.ExitOnError)
|
||||
configPath := fset.String("config", "/etc/archivmail/config.yml", "path to config file")
|
||||
dryRun := fset.Bool("dry-run", false, "simulate without writing changes")
|
||||
_ = fset.Parse(args)
|
||||
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelInfo}))
|
||||
|
||||
cfg, err := config.Load(*configPath)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: load config: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
storeCfg := storage.Config{
|
||||
Dir: cfg.Storage.StorePath,
|
||||
Keyfile: cfg.Storage.Keyfile,
|
||||
DSN: cfg.Database.DSN(),
|
||||
CompressEnabled: cfg.Storage.Compress,
|
||||
}
|
||||
mailStore, err := storage.New(storeCfg)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: storage init: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer mailStore.Close()
|
||||
|
||||
if *dryRun {
|
||||
logger.Info("rethread: DRY-RUN — keine Änderungen werden gespeichert")
|
||||
}
|
||||
|
||||
stats, err := mailStore.Rethread(context.Background(), *dryRun, logger)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error: rethread: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger.Info("rethread: abgeschlossen",
|
||||
"total", stats.Total,
|
||||
"updated", stats.Updated,
|
||||
"skipped", stats.Skipped,
|
||||
"errors", stats.Errors,
|
||||
)
|
||||
|
||||
if stats.Errors > 0 {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,9 @@ func main() {
|
||||
case "recompress":
|
||||
runRecompress(os.Args[2:])
|
||||
return
|
||||
case "rethread":
|
||||
runRethread(os.Args[2:])
|
||||
return
|
||||
case "version":
|
||||
fmt.Printf("archivmail %s\n", AppVersion)
|
||||
for mod, ver := range Modules {
|
||||
|
||||
Reference in New Issue
Block a user