Fix mailbox UI sorting and target layout

This commit is contained in:
DonVoo 2026-07-15 00:14:54 +02:00
parent 8e8c651eaa
commit e63a513cff
6 changed files with 196 additions and 46 deletions

View file

@ -12,6 +12,7 @@ import (
"net/mail"
"os"
"path/filepath"
"sort"
"strings"
"time"
@ -166,6 +167,7 @@ func ReadMboxList(path string) ([]MboxEntry, error) {
Date: decodeHeader(msg.Header.Get("Date")),
})
}
sortMboxEntriesByDateDesc(out)
return out, nil
}
@ -467,6 +469,14 @@ func readMboxListFromIndex(path string) ([]MboxEntry, bool) {
if err != nil || len(index) == 0 {
return nil, false
}
sort.SliceStable(index, func(i, j int) bool {
di := parseMboxIndexDate(index[i].Date)
dj := parseMboxIndexDate(index[j].Date)
if !di.Equal(dj) {
return di.After(dj)
}
return index[i].Seq > index[j].Seq
})
out := make([]MboxEntry, 0, len(index))
for _, entry := range index {
out = append(out, MboxEntry{
@ -479,6 +489,25 @@ func readMboxListFromIndex(path string) ([]MboxEntry, bool) {
return out, true
}
func sortMboxEntriesByDateDesc(entries []MboxEntry) {
sort.SliceStable(entries, func(i, j int) bool {
di := parseMboxIndexDate(entries[i].Date)
dj := parseMboxIndexDate(entries[j].Date)
if !di.Equal(dj) {
return di.After(dj)
}
return entries[i].Index > entries[j].Index
})
}
func parseMboxIndexDate(value string) time.Time {
t, err := mail.ParseDate(strings.TrimSpace(value))
if err == nil {
return t
}
return time.Time{}
}
func readMboxMessageFromIndex(path string, index int) ([]byte, bool, error) {
accountID, folder, ok := mboxIndexContext(path)
if !ok {