Show archive folder counts
This commit is contained in:
parent
514a7723bf
commit
422308e7e6
3 changed files with 97 additions and 6 deletions
|
|
@ -43,9 +43,9 @@ func renderShell(w http.ResponseWriter, active, readingPane string) {
|
|||
fmt.Fprintf(w, `<!doctype html><html lang="de"><head><meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<title>Mail-Graveyard</title>
|
||||
<link rel="stylesheet" href="/static/style.css?v=20260706-6">
|
||||
<link rel="stylesheet" href="/static/style.css?v=20260712-1">
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<script src="/static/app.js?v=20260706-6" defer></script></head>
|
||||
<script src="/static/app.js?v=20260712-1" defer></script></head>
|
||||
<body class="ol2013">
|
||||
<header class="ribbon">
|
||||
<nav class="ribbon-tabs">
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"net/mail"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
|
@ -126,10 +127,9 @@ func renderViewerTree(w http.ResponseWriter) {
|
|||
found = true
|
||||
source := sourceDisplayLabel(account)
|
||||
fmt.Fprintf(w, `<div class="tree-node account">%s</div>`, html.EscapeString(sourceDisplayLabel(account)))
|
||||
for _, path := range mboxes {
|
||||
folder := strings.TrimSuffix(filepath.Base(path), ".mbox")
|
||||
fmt.Fprintf(w, `<a class="tree-node" href="#" hx-get="/view?source=%s&folder=%s" hx-target="#list" hx-swap="innerHTML">%s</a>`,
|
||||
urlEsc(source), urlEsc(folder), html.EscapeString(folder))
|
||||
for _, folder := range archiveFolderInfos(mboxes) {
|
||||
fmt.Fprintf(w, `<a class="tree-node folder" href="#" hx-get="/view?source=%s&folder=%s" hx-target="#list" hx-swap="innerHTML"><span class="tree-label">%s</span><span class="tree-count">%d</span></a>`,
|
||||
urlEsc(source), urlEsc(folder.Name), html.EscapeString(folder.Label), folder.Count)
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
|
|
@ -181,6 +181,82 @@ func renderMessageList(w http.ResponseWriter, account, folder, q string) {
|
|||
}
|
||||
}
|
||||
|
||||
type archiveFolderInfo struct {
|
||||
Name string
|
||||
Label string
|
||||
Count int
|
||||
}
|
||||
|
||||
func archiveFolderInfos(paths []string) []archiveFolderInfo {
|
||||
out := make([]archiveFolderInfo, 0, len(paths))
|
||||
for _, path := range paths {
|
||||
name := strings.TrimSuffix(filepath.Base(path), ".mbox")
|
||||
entries, err := ReadMboxList(path)
|
||||
count := 0
|
||||
if err == nil {
|
||||
count = len(entries)
|
||||
}
|
||||
out = append(out, archiveFolderInfo{
|
||||
Name: name,
|
||||
Label: archiveFolderLabel(name),
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
sort.SliceStable(out, func(i, j int) bool {
|
||||
return archiveFolderSortKey(out[i].Name) < archiveFolderSortKey(out[j].Name)
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
func archiveFolderLabel(name string) string {
|
||||
name = strings.TrimSpace(name)
|
||||
switch strings.ToLower(name) {
|
||||
case "", "inbox":
|
||||
return "Posteingang"
|
||||
case "drafts", "entw&apw-rfe", "entwürfe", "entwuerfe":
|
||||
return "Entwürfe"
|
||||
case "sent", "gesendet", "gesendete", "gesendete objekte", "gesendete elemente":
|
||||
return "Gesendet"
|
||||
case "trash", "papierkorb", "gelöscht", "geloescht", "gelöschte objekte", "geloeschte objekte":
|
||||
return "Papierkorb"
|
||||
case "archive", "archiv":
|
||||
return "Archiv"
|
||||
case "spam", "junk":
|
||||
return "Spam"
|
||||
}
|
||||
parts := strings.FieldsFunc(name, func(r rune) bool {
|
||||
return r == '/' || r == '\\'
|
||||
})
|
||||
if len(parts) == 0 {
|
||||
parts = strings.Split(name, "_")
|
||||
}
|
||||
label := strings.TrimSpace(parts[len(parts)-1])
|
||||
if label == "" {
|
||||
return name
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
func archiveFolderSortKey(name string) string {
|
||||
lc := strings.ToLower(strings.TrimSpace(name))
|
||||
switch lc {
|
||||
case "inbox":
|
||||
return "00:" + lc
|
||||
case "drafts", "entw&apw-rfe", "entwürfe", "entwuerfe":
|
||||
return "01:" + lc
|
||||
case "sent", "gesendet", "gesendete", "gesendete objekte", "gesendete elemente":
|
||||
return "02:" + lc
|
||||
case "spam", "junk":
|
||||
return "03:" + lc
|
||||
case "trash", "papierkorb", "gelöscht", "geloescht", "gelöschte objekte", "geloeschte objekte":
|
||||
return "04:" + lc
|
||||
case "archive", "archiv":
|
||||
return "05:" + lc
|
||||
default:
|
||||
return "10:" + lc
|
||||
}
|
||||
}
|
||||
|
||||
func manualCopyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue