aboutsummaryrefslogtreecommitdiffstats
path: root/commands/account
diff options
context:
space:
mode:
authorVitaly Ovchinnikov <v@postbox.nz>2023-08-04 15:33:34 +0300
committerRobin Jarry <robin@jarry.cc>2023-08-05 00:04:35 +0200
commit4a8ae421690b915db9b2917b9e9df9d66cc910c6 (patch)
tree0214e51b638a2fcd704b7b2fa105a21697b462db /commands/account
parent1144611a1626d8f5d7ffe02d76ea58a97a67aff4 (diff)
downloadaerc-4a8ae421690b915db9b2917b9e9df9d66cc910c6.tar.gz
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 <v@postbox.nz> Acked-by: Robin Jarry <robin@jarry.cc> Tested-by: Koni Marti <koni.marti@gmail.com>
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/export-mbox.go26
1 files changed, 23 insertions, 3 deletions
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)
}()