Add archive mailbox selector
This commit is contained in:
parent
422308e7e6
commit
cff776dc8c
3 changed files with 94 additions and 34 deletions
|
|
@ -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