Add optional zstd mbox archives

This commit is contained in:
DonVoo 2026-07-14 20:20:30 +02:00
parent 21844688ac
commit e612896e06
14 changed files with 620 additions and 39 deletions

View file

@ -138,7 +138,7 @@ func renderViewerTree(w http.ResponseWriter, selected string) {
}
fmt.Fprint(w, `</select></form></div>`)
mboxes, _ := filepath.Glob(filepath.Join(Cfg.MboxRoot, selected, "*.mbox"))
mboxes := archiveMboxPaths(filepath.Join(Cfg.MboxRoot, selected))
if len(mboxes) == 0 {
fmt.Fprint(w, `<div class="ef-empty">Keine Ordner in dieser Archiv-Mailbox.</div>`)
return
@ -203,7 +203,7 @@ type archiveFolderInfo struct {
func archiveFolderInfos(paths []string) []archiveFolderInfo {
out := make([]archiveFolderInfo, 0, len(paths))
for _, path := range paths {
name := strings.TrimSuffix(filepath.Base(path), ".mbox")
name := folderNameFromMboxPath(path)
entries, err := ReadMboxList(path)
count := 0
if err == nil {
@ -409,7 +409,15 @@ func mboxPath(account, folder string) (string, error) {
if err != nil {
return "", err
}
path, err := filepath.Abs(filepath.Join(root, account, safeMboxName(folder)+".mbox"))
plain := filepath.Join(root, account, safeMboxName(folder)+".mbox")
compressed := plain + ".zst"
selected := plain
if _, err := os.Stat(plain); err != nil && os.IsNotExist(err) {
if _, zstErr := os.Stat(compressed); zstErr == nil {
selected = compressed
}
}
path, err := filepath.Abs(selected)
if err != nil {
return "", err
}
@ -540,7 +548,7 @@ func findForwardedCopy(account, targetAccount string, raw []byte) (forwardedMatc
if targetAccount != "" && !allowedTargets[entry.Name()] {
continue
}
mboxes, _ := filepath.Glob(filepath.Join(Cfg.MboxRoot, entry.Name(), "*.mbox"))
mboxes := archiveMboxPaths(filepath.Join(Cfg.MboxRoot, entry.Name()))
for _, path := range mboxes {
msgs, err := ReadMboxList(path)
if err != nil {
@ -554,7 +562,7 @@ func findForwardedCopy(account, targetAccount string, raw []byte) (forwardedMatc
if messageIDHeader(candidate) == id {
return forwardedMatch{
Account: entry.Name(),
Folder: strings.TrimSuffix(filepath.Base(path), ".mbox"),
Folder: folderNameFromMboxPath(path),
Index: msg.Index,
Raw: candidate,
}, true
@ -716,7 +724,7 @@ func viewerAccounts() []viewerAccount {
if !entry.IsDir() {
continue
}
mboxes, _ := filepath.Glob(filepath.Join(Cfg.MboxRoot, entry.Name(), "*.mbox"))
mboxes := archiveMboxPaths(filepath.Join(Cfg.MboxRoot, entry.Name()))
if len(mboxes) == 0 {
continue
}