From 4a8ae421690b915db9b2917b9e9df9d66cc910c6 Mon Sep 17 00:00:00 2001 From: Vitaly Ovchinnikov Date: Fri, 4 Aug 2023 15:33:34 +0300 Subject: export-mbox: only export marked messages, if any Change the `:export-mbox` behavior, so if some messages are marked with `:mark` - only those messages are exported. If nothing is marked - the whole folder is exported, as usual. Signed-off-by: Vitaly Ovchinnikov Acked-by: Robin Jarry Tested-by: Koni Marti --- commands/account/export-mbox.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'commands/account/export-mbox.go') diff --git a/commands/account/export-mbox.go b/commands/account/export-mbox.go index 5051906c..1f4c5a42 100644 --- a/commands/account/export-mbox.go +++ b/commands/account/export-mbox.go @@ -52,6 +52,21 @@ func (ExportMbox) Execute(aerc *widgets.Aerc, args []string) error { aerc.PushStatus("Exporting to "+filename, 10*time.Second) + // uids of messages to export + var uids []uint32 + + // check if something is marked - we export that then + msgProvider, ok := aerc.SelectedTabContent().(widgets.ProvidesMessages) + if !ok { + msgProvider = aerc.SelectedAccount() + } + if msgProvider != nil { + marked, err := msgProvider.MarkedMessages() + if err == nil && len(marked) > 0 { + uids = marked + } + } + go func() { defer log.PanicHandler() file, err := os.Create(filename) @@ -67,9 +82,14 @@ func (ExportMbox) Execute(aerc *widgets.Aerc, args []string) error { var retries int done := make(chan bool) - uids := make([]uint32, len(store.Uids())) - copy(uids, store.Uids()) + + // 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) for len(uids) > 0 { if retries > 0 { @@ -116,7 +136,7 @@ func (ExportMbox) Execute(aerc *widgets.Aerc, args []string) error { } retries++ } - statusInfo := fmt.Sprintf("Exported %d of %d messages to %s.", ctr, len(store.Uids()), filename) + statusInfo := fmt.Sprintf("Exported %d of %d messages to %s.", ctr, total, filename) aerc.PushStatus(statusInfo, 10*time.Second) log.Debugf(statusInfo) }() -- cgit