aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaly Ovchinnikov <v@postbox.nz>2023-09-25 15:38:06 +0000
committerRobin Jarry <robin@jarry.cc>2023-10-22 15:14:34 +0200
commit8c576798d5aa7afdbf0c3f787e3fbbcce0a82c39 (patch)
tree05058dbab22a6bced0c4e00a63d420e5c56a962a
parent863e124e8437ac2f5a92fe3f291b7e7e022787fc (diff)
downloadaerc-8c576798d5aa7afdbf0c3f787e3fbbcce0a82c39.tar.gz
aerc-8c576798d5aa7afdbf0c3f787e3fbbcce0a82c39.zip
export-mbox: preserve the user-visible sorting order when exporting
Export messages to mbox format in the same order as they are displayed to the user. Both marked-only and "full" export modes are supported. Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/account/export-mbox.go53
1 files changed, 47 insertions, 6 deletions
diff --git a/commands/account/export-mbox.go b/commands/account/export-mbox.go
index e9a663c5..a17b8a29 100644
--- a/commands/account/export-mbox.go
+++ b/commands/account/export-mbox.go
@@ -10,6 +10,7 @@ import (
"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
+ "git.sr.ht/~rjarry/aerc/lib"
"git.sr.ht/~rjarry/aerc/log"
mboxer "git.sr.ht/~rjarry/aerc/worker/mbox"
"git.sr.ht/~rjarry/aerc/worker/types"
@@ -66,7 +67,19 @@ func (ExportMbox) Execute(args []string) error {
if msgProvider != nil {
marked, err := msgProvider.MarkedMessages()
if err == nil && len(marked) > 0 {
- uids = marked
+ uids, err = sortMarkedUids(marked, store)
+ if err != nil {
+ return err
+ }
+ }
+ }
+
+ // if no messages were marked, we export everything
+ if len(uids) == 0 {
+ var err error
+ uids, err = sortAllUids(store)
+ if err != nil {
+ return err
}
}
@@ -86,11 +99,6 @@ func (ExportMbox) Execute(args []string) error {
done := make(chan bool)
- // if no messages were marked, we export everything
- if len(uids) == 0 {
- uids = make([]uint32, len(store.Uids()))
- copy(uids, store.Uids())
- }
t := time.Now()
total := len(uids)
@@ -150,3 +158,36 @@ func (ExportMbox) Execute(args []string) error {
func exportFolderUsage(cmd string) error {
return fmt.Errorf("Usage: %s <filename>", cmd)
}
+
+func sortMarkedUids(marked []uint32, store *lib.MessageStore) ([]uint32, error) {
+ lookup := map[uint32]bool{}
+ for _, uid := range marked {
+ lookup[uid] = true
+ }
+ uids := []uint32{}
+ iter := store.UidsIterator()
+ for iter.Next() {
+ uid, ok := iter.Value().(uint32)
+ if !ok {
+ return nil, errors.New("Invalid message UID value")
+ }
+ _, marked := lookup[uid]
+ if marked {
+ uids = append(uids, uid)
+ }
+ }
+ return uids, nil
+}
+
+func sortAllUids(store *lib.MessageStore) ([]uint32, error) {
+ uids := []uint32{}
+ iter := store.UidsIterator()
+ for iter.Next() {
+ uid, ok := iter.Value().(uint32)
+ if !ok {
+ return nil, errors.New("Invalid message UID value")
+ }
+ uids = append(uids, uid)
+ }
+ return uids, nil
+}