Decouple archive mailboxes from accounts
This commit is contained in:
parent
0bb49019b6
commit
8d2838aea7
4 changed files with 130 additions and 46 deletions
|
|
@ -685,6 +685,20 @@ type targetAccountOption struct {
|
|||
|
||||
func viewerAccounts() []viewerAccount {
|
||||
labels := accountLabels()
|
||||
if DB != nil {
|
||||
archives, err := ListArchiveMailboxes()
|
||||
if err == nil {
|
||||
out := make([]viewerAccount, 0, len(archives))
|
||||
for _, archive := range archives {
|
||||
a := labels[archive]
|
||||
if a.Name == "" {
|
||||
a = viewerAccount{Name: archive, SourceLabel: archive, DisplayLabel: "Archiv-mbox: " + archive}
|
||||
}
|
||||
out = append(out, a)
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
entries, err := os.ReadDir(Cfg.MboxRoot)
|
||||
if err != nil {
|
||||
return nil
|
||||
|
|
@ -700,7 +714,7 @@ func viewerAccounts() []viewerAccount {
|
|||
}
|
||||
a := labels[entry.Name()]
|
||||
if a.Name == "" {
|
||||
a = viewerAccount{Name: entry.Name(), SourceLabel: entry.Name(), DisplayLabel: "Original"}
|
||||
a = viewerAccount{Name: entry.Name(), SourceLabel: entry.Name(), DisplayLabel: "Archiv-mbox: " + entry.Name()}
|
||||
}
|
||||
out = append(out, a)
|
||||
}
|
||||
|
|
@ -711,7 +725,7 @@ func sourceDisplayLabel(mboxDir string) string {
|
|||
if a := accountLabels()[mboxDir]; a.DisplayLabel != "" {
|
||||
return a.DisplayLabel
|
||||
}
|
||||
return "Original"
|
||||
return "Archiv-mbox: " + mboxDir
|
||||
}
|
||||
|
||||
func sourceAccountLabel(mboxDir string) string {
|
||||
|
|
@ -749,6 +763,9 @@ func accountLabels() map[string]viewerAccount {
|
|||
n := 0
|
||||
for _, a := range accounts {
|
||||
dir := accountMboxDir(a)
|
||||
if dir == "" {
|
||||
continue
|
||||
}
|
||||
source := a.SrcUser
|
||||
if source == "" {
|
||||
source = a.Name
|
||||
|
|
@ -768,7 +785,7 @@ func accountByMboxDir(mboxDir string) (Account, bool) {
|
|||
return Account{}, false
|
||||
}
|
||||
for _, a := range accounts {
|
||||
if accountMboxDir(a) == mboxDir {
|
||||
if dir := accountMboxDir(a); dir != "" && dir == mboxDir {
|
||||
return a, true
|
||||
}
|
||||
}
|
||||
|
|
@ -841,15 +858,14 @@ func targetMboxDirs(targetUser string) map[string]bool {
|
|||
}
|
||||
for _, a := range accounts {
|
||||
if strings.EqualFold(strings.TrimSpace(a.DstUser), targetUser) {
|
||||
out[accountMboxDir(a)] = true
|
||||
if dir := accountMboxDir(a); dir != "" {
|
||||
out[dir] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func accountMboxDir(a Account) string {
|
||||
if strings.TrimSpace(a.MboxDir) != "" {
|
||||
return a.MboxDir
|
||||
}
|
||||
return a.Name
|
||||
return strings.TrimSpace(a.MboxDir)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue