Decouple archive mailboxes from accounts
This commit is contained in:
parent
0bb49019b6
commit
8d2838aea7
4 changed files with 130 additions and 46 deletions
|
|
@ -160,6 +160,11 @@ func accountsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
archives, err := ListArchiveMailboxes()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
editName := strings.TrimSpace(r.URL.Query().Get("edit"))
|
||||
var edit Account
|
||||
if editName != "" {
|
||||
|
|
@ -169,7 +174,7 @@ func accountsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
}
|
||||
renderAccountsPage(w, r, accounts, edit, r.URL.Query().Get("msg"), r.URL.Query().Get("err"))
|
||||
renderAccountsPage(w, r, accounts, archives, edit, r.URL.Query().Get("msg"), r.URL.Query().Get("err"))
|
||||
}
|
||||
|
||||
func accountSaveHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -253,7 +258,12 @@ func archivesHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
renderArchivesPage(w, r, archiveMailboxes(accounts), accounts, r.URL.Query().Get("msg"), r.URL.Query().Get("err"))
|
||||
archives, err := ListArchiveMailboxes()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
renderArchivesPage(w, r, archives, accounts, r.URL.Query().Get("msg"), r.URL.Query().Get("err"))
|
||||
}
|
||||
|
||||
func transferHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -270,7 +280,12 @@ func transferHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
renderTransferPage(w, r, transferModeBySlug(mode), accounts, archiveMailboxes(accounts))
|
||||
archives, err := ListArchiveMailboxes()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
renderTransferPage(w, r, transferModeBySlug(mode), accounts, archives)
|
||||
}
|
||||
|
||||
func emailBoxHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -307,6 +322,10 @@ func archiveCreateHandler(w http.ResponseWriter, r *http.Request) {
|
|||
redirectArchives(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
if err := SaveArchiveMailbox(name); err != nil {
|
||||
redirectArchives(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
redirectArchives(w, r, "Archiv-Mailbox angelegt.")
|
||||
}
|
||||
|
||||
|
|
@ -330,7 +349,11 @@ func archiveDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
path := filepath.Join(Cfg.MboxRoot, name)
|
||||
entries, err := os.ReadDir(path)
|
||||
if os.IsNotExist(err) {
|
||||
redirectArchives(w, r, "Archiv-Mailbox existiert nicht.")
|
||||
if err := DeleteArchiveMailbox(name); err != nil {
|
||||
redirectArchives(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
redirectArchives(w, r, "Archiv-Mailbox entfernt.")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
|
|
@ -345,6 +368,10 @@ func archiveDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
redirectArchives(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
if err := DeleteArchiveMailbox(name); err != nil {
|
||||
redirectArchives(w, r, err.Error())
|
||||
return
|
||||
}
|
||||
redirectArchives(w, r, "Leere Archiv-Mailbox entfernt.")
|
||||
}
|
||||
|
||||
|
|
@ -542,12 +569,11 @@ func userToggleActiveHandler(w http.ResponseWriter, r *http.Request) {
|
|||
redirectUsers(w, r, username, "Benutzer aktiviert.")
|
||||
}
|
||||
|
||||
func renderAccountsPage(w http.ResponseWriter, r *http.Request, accounts []Account, edit Account, msg, errMsg string) {
|
||||
func renderAccountsPage(w http.ResponseWriter, r *http.Request, accounts []Account, archives []string, edit Account, msg, errMsg string) {
|
||||
user := CurrentUser(r)
|
||||
if edit.Name == "" {
|
||||
edit = Account{SrcPort: 993, SrcSecurity: "tls", SrcProto: "imap", DstPort: 993, DstSecurity: "tls", Active: true}
|
||||
}
|
||||
archives := archiveMailboxes(accounts)
|
||||
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">
|
||||
|
|
@ -1183,8 +1209,9 @@ func renderArchiveForm(w http.ResponseWriter) {
|
|||
<button class="btn" type="submit">Erstellen</button>
|
||||
</form>
|
||||
<div class="archive-help">
|
||||
<div class="archive-help-title">Schutzlogik</div>
|
||||
<p>Archiv-mboxen werden als lokale Ordner unter dem Backup-Root angelegt.</p>
|
||||
<div class="archive-help-title">Archivlogik</div>
|
||||
<p>Archiv-mboxen sind eigenstaendige Mailboxen und nicht von einem Quellkonto abhaengig.</p>
|
||||
<p>Sie koennen leer angelegt oder spaeter per Import mit mbox/PST-Inhalten gefuellt werden.</p>
|
||||
<p>Entfernen ist nur moeglich, wenn die Mailbox keinem Konto zugeordnet und leer ist.</p>
|
||||
</div>`)
|
||||
}
|
||||
|
|
@ -1282,7 +1309,7 @@ func archiveSelect(current string, archives []string) string {
|
|||
values = append([]string{current}, values...)
|
||||
}
|
||||
if len(values) == 0 {
|
||||
return `<input class="input" name="mbox_dir" placeholder="erst Archiv-Mailbox erstellen">`
|
||||
return `<select name="mbox_dir" disabled><option>erst Archiv-Mailbox erstellen</option></select>`
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString(`<select name="mbox_dir">`)
|
||||
|
|
@ -1323,30 +1350,6 @@ func parsePort(value string) int {
|
|||
return port
|
||||
}
|
||||
|
||||
func archiveMailboxes(accounts []Account) []string {
|
||||
seen := map[string]bool{}
|
||||
for _, a := range accounts {
|
||||
name := accountMboxDir(a)
|
||||
if name != "" {
|
||||
seen[name] = true
|
||||
}
|
||||
}
|
||||
entries, err := os.ReadDir(Cfg.MboxRoot)
|
||||
if err == nil {
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
seen[entry.Name()] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
out := make([]string, 0, len(seen))
|
||||
for name := range seen {
|
||||
out = append(out, name)
|
||||
}
|
||||
sortStrings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
func archiveUses(archive string, accounts []Account) string {
|
||||
var uses []string
|
||||
for _, a := range accounts {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue