From 132389fdeda8e43071a287ff42e2a3a86086f5a9 Mon Sep 17 00:00:00 2001 From: Maxime PAYET Date: Tue, 8 Jun 2021 16:14:40 +0200 Subject: [PATCH] Sort mail by date when using maildir --- maildir.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/maildir.go b/maildir.go index d102549..5785d38 100644 --- a/maildir.go +++ b/maildir.go @@ -7,7 +7,7 @@ import ( "os" "path/filepath" "strings" - + "sort" "github.com/mailhog/data" ) @@ -138,6 +138,11 @@ func (maildir *Maildir) List(start, limit int) (*data.Messages, error) { if err != nil { return nil, err } + sort.Slice(n, func(i, j int) bool { + return n[i].ModTime().After(n[j].ModTime()) + }) + + for _, fileinfo := range n { b, err := ioutil.ReadFile(filepath.Join(maildir.Path, fileinfo.Name()))