diff --git a/backend/08-viewer.go b/backend/08-viewer.go
index a719c38..2fdb243 100644
--- a/backend/08-viewer.go
+++ b/backend/08-viewer.go
@@ -283,6 +283,7 @@ func findForwardedCopy(account, targetAccount string, raw []byte) (forwardedMatc
if id == "" {
return forwardedMatch{}, false
}
+ allowedTargets := targetMboxDirs(targetAccount)
entries, err := os.ReadDir(Cfg.MboxRoot)
if err != nil {
return forwardedMatch{}, false
@@ -291,7 +292,7 @@ func findForwardedCopy(account, targetAccount string, raw []byte) (forwardedMatc
if !entry.IsDir() || entry.Name() == account {
continue
}
- if targetAccount != "" && entry.Name() != targetAccount {
+ if targetAccount != "" && !allowedTargets[entry.Name()] {
continue
}
mboxes, _ := filepath.Glob(filepath.Join(Cfg.MboxRoot, entry.Name(), "*.mbox"))
@@ -328,10 +329,7 @@ func messageIDHeader(raw []byte) string {
}
func renderTargetAccountSelect(account, folder, selected string, index int) string {
- accounts := viewerAccounts()
- if selected == account {
- selected = ""
- }
+ options := targetAccountOptions()
var b strings.Builder
fmt.Fprintf(&b, `
Zielkopie
`)
return b.String()
@@ -360,7 +355,11 @@ func renderTargetAccountSelect(account, folder, selected string, index int) stri
type viewerAccount struct {
Name string
SourceLabel string
- TargetLabel string
+}
+
+type targetAccountOption struct {
+ Value string
+ Label string
}
func viewerAccounts() []viewerAccount {
@@ -380,7 +379,7 @@ func viewerAccounts() []viewerAccount {
}
a := labels[entry.Name()]
if a.Name == "" {
- a = viewerAccount{Name: entry.Name(), SourceLabel: entry.Name(), TargetLabel: entry.Name()}
+ a = viewerAccount{Name: entry.Name(), SourceLabel: entry.Name()}
}
out = append(out, a)
}
@@ -409,14 +408,45 @@ func accountLabels() map[string]viewerAccount {
if source == "" {
source = a.Name
}
- target := a.DstUser
- if target == "" {
- target = a.Name
+ out[dir] = viewerAccount{Name: dir, SourceLabel: source}
+ }
+ return out
+}
+
+func targetAccountOptions() []targetAccountOption {
+ if DB == nil {
+ return nil
+ }
+ accounts, err := ListAccounts()
+ if err != nil {
+ return nil
+ }
+ seen := map[string]bool{}
+ var out []targetAccountOption
+ for _, a := range accounts {
+ target := strings.TrimSpace(a.DstUser)
+ if target == "" || seen[target] {
+ continue
}
- if a.Name != "" {
- target = target + " (" + a.Name + ")"
+ seen[target] = true
+ out = append(out, targetAccountOption{Value: target, Label: target})
+ }
+ return out
+}
+
+func targetMboxDirs(targetUser string) map[string]bool {
+ out := map[string]bool{}
+ if targetUser == "" || DB == nil {
+ return out
+ }
+ accounts, err := ListAccounts()
+ if err != nil {
+ return out
+ }
+ for _, a := range accounts {
+ if strings.EqualFold(strings.TrimSpace(a.DstUser), targetUser) {
+ out[accountMboxDir(a)] = true
}
- out[dir] = viewerAccount{Name: dir, SourceLabel: source, TargetLabel: target}
}
return out
}