Add archive mailbox selector
This commit is contained in:
parent
422308e7e6
commit
cff776dc8c
3 changed files with 94 additions and 34 deletions
|
|
@ -10,12 +10,12 @@ func RegisterRoutes(mux *http.ServeMux) {
|
|||
mux.HandleFunc("/login", loginHandler)
|
||||
|
||||
// Umzug (Konten pflegen + starten/beobachten)
|
||||
mux.HandleFunc("/accounts", accountsHandler) // TODO Codex (02/07)
|
||||
mux.HandleFunc("/accounts/save", accountSaveHandler) // TODO Codex
|
||||
mux.HandleFunc("/accounts", accountsHandler) // TODO Codex (02/07)
|
||||
mux.HandleFunc("/accounts/save", accountSaveHandler) // TODO Codex
|
||||
mux.HandleFunc("/accounts/delete", accountDeleteHandler) // TODO Codex
|
||||
mux.HandleFunc("/accounts/test", accountTestHandler) // TODO Codex: Quelle+Ziel-Login pruefen
|
||||
mux.HandleFunc("/migrate/run", migrateRunHandler) // TODO Codex: RunMigration im Hintergrund
|
||||
mux.HandleFunc("/migrate/status", migrateStatusHandler) // TODO Codex: jobs-Fortschritt (HTMX-Poll)
|
||||
mux.HandleFunc("/accounts/test", accountTestHandler) // TODO Codex: Quelle+Ziel-Login pruefen
|
||||
mux.HandleFunc("/migrate/run", migrateRunHandler) // TODO Codex: RunMigration im Hintergrund
|
||||
mux.HandleFunc("/migrate/status", migrateStatusHandler) // TODO Codex: jobs-Fortschritt (HTMX-Poll)
|
||||
|
||||
// Viewer (lokale mbox betrachten + weiterleiten)
|
||||
mux.HandleFunc("/view", viewerHandler)
|
||||
|
|
@ -36,20 +36,21 @@ func homeHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
// renderShell ist das Grundgeruest im Outlook-2013-Look:
|
||||
// [ Ribbon: Archiv-Boxen | Import/Export | Postfach-Verwaltung | Mail-Transfer | Einstellungen | Mail-Graveyard ]
|
||||
// [ Archiv-mbox | Nachrichtenliste | Quelle/Target ]
|
||||
//
|
||||
// [ Ribbon: Archiv-Boxen | Import/Export | Postfach-Verwaltung | Mail-Transfer | Einstellungen | Mail-Graveyard ]
|
||||
// [ Archiv-mbox | Nachrichtenliste | Quelle/Target ]
|
||||
func renderShell(w http.ResponseWriter, active, readingPane string) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
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=20260712-1">
|
||||
<link rel="stylesheet" href="/static/style.css?v=20260712-2">
|
||||
<script src="/static/htmx.min.js"></script>
|
||||
<script src="/static/app.js?v=20260712-1" defer></script></head>
|
||||
<script src="/static/app.js?v=20260712-2" defer></script></head>
|
||||
<body class="ol2013">
|
||||
<header class="ribbon">
|
||||
<nav class="ribbon-tabs">
|
||||
<a class="tab %s" href="/view">Archiv-Boxen</a>
|
||||
<a class="tab %s" href="/view"><span class="mail-logo" aria-hidden="true"></span><span>Archiv-Boxen</span></a>
|
||||
<a class="tab" href="/view">Import/Export</a>
|
||||
<a class="tab" href="/accounts">Postfach-Verwaltung</a>
|
||||
<a class="tab" href="/view">Mail-Transfer</a>
|
||||
|
|
@ -60,7 +61,7 @@ func renderShell(w http.ResponseWriter, active, readingPane string) {
|
|||
<div class="three-pane">
|
||||
<aside class="pane pane-tree" id="tree"
|
||||
hx-get="/view" hx-trigger="load" hx-target="#tree" hx-swap="innerHTML">
|
||||
<div class="pane-head">Postfächer</div>
|
||||
<div class="pane-head">Archiv-Mailbox</div>
|
||||
</aside>
|
||||
<div class="pane-resizer" data-resize-index="0"></div>
|
||||
<section class="pane pane-list" id="list">
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func viewerHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
renderViewerTree(w)
|
||||
renderViewerTree(w, account)
|
||||
return
|
||||
}
|
||||
renderShell(w, "", `<div class="ef-empty">Backup-Postfach links waehlen.</div>`)
|
||||
|
|
@ -106,34 +106,47 @@ func forwardHandler(w http.ResponseWriter, r *http.Request) {
|
|||
// selbst nutzt IMAP APPEND.
|
||||
}
|
||||
|
||||
func renderViewerTree(w http.ResponseWriter) {
|
||||
func renderViewerTree(w http.ResponseWriter, selected string) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
fmt.Fprint(w, `<div class="pane-head">Originale</div>`)
|
||||
entries, err := os.ReadDir(Cfg.MboxRoot)
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, `<div class="ef-empty">%s</div>`, html.EscapeString(err.Error()))
|
||||
accounts := viewerAccounts()
|
||||
if len(accounts) == 0 {
|
||||
fmt.Fprint(w, `<div class="pane-head archive-head"><span>Archiv-Mailbox</span></div><div class="ef-empty">Noch keine mbox-Backups.</div>`)
|
||||
return
|
||||
}
|
||||
found := false
|
||||
for _, entry := range entries {
|
||||
if !entry.IsDir() {
|
||||
continue
|
||||
selected = resolveViewerAccount(selected, selected)
|
||||
if selected == "" {
|
||||
selected = accounts[0].Name
|
||||
} else {
|
||||
found := false
|
||||
for _, account := range accounts {
|
||||
if account.Name == selected {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
account := entry.Name()
|
||||
mboxes, _ := filepath.Glob(filepath.Join(Cfg.MboxRoot, account, "*.mbox"))
|
||||
if len(mboxes) == 0 {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
source := sourceDisplayLabel(account)
|
||||
fmt.Fprintf(w, `<div class="tree-node account">%s</div>`, html.EscapeString(sourceDisplayLabel(account)))
|
||||
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 {
|
||||
selected = accounts[0].Name
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
fmt.Fprint(w, `<div class="ef-empty">Noch keine mbox-Backups.</div>`)
|
||||
fmt.Fprint(w, `<div class="pane-head archive-head"><span>Archiv-Mailbox</span><form class="archive-select-form" hx-get="/view" hx-target="#tree" hx-swap="innerHTML" hx-trigger="change from:#archive-mailbox-select"><select id="archive-mailbox-select" class="archive-select" name="source">`)
|
||||
for _, account := range accounts {
|
||||
attr := ""
|
||||
if account.Name == selected {
|
||||
attr = ` selected`
|
||||
}
|
||||
fmt.Fprintf(w, `<option value="%s"%s>%s</option>`, html.EscapeString(account.DisplayLabel), attr, html.EscapeString(account.SourceLabel))
|
||||
}
|
||||
fmt.Fprint(w, `</select></form></div>`)
|
||||
|
||||
mboxes, _ := filepath.Glob(filepath.Join(Cfg.MboxRoot, selected, "*.mbox"))
|
||||
if len(mboxes) == 0 {
|
||||
fmt.Fprint(w, `<div class="ef-empty">Keine Ordner in dieser Archiv-Mailbox.</div>`)
|
||||
return
|
||||
}
|
||||
source := sourceDisplayLabel(selected)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue