aboutsummaryrefslogtreecommitdiff
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
parent1144611a1626d8f5d7ffe02d76ea58a97a67aff4 (diff)
downloadaerc-4a8ae421690b915db9b2917b9e9df9d66cc910c6.tar.gz
aerc-4a8ae421690b915db9b2917b9e9df9d66cc910c6.zip
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>
-rw-r--r--CHANGELOG.md2
-rw-r--r--commands/account/export-mbox.go26
-rw-r--r--doc/aerc.1.scd4
3 files changed, 28 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e84982e..29fba540 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
**prepended** to the default system `PATH` to avoid conflicts with installed
distro binaries which have the same name as aerc builtin filters (e.g.
`/usr/bin/colorize`).
+- `:export-mbox` only exports marked messages, if any. Otherwise it exports
+ everything, as usual.
## [0.15.2](https://git.sr.ht/~rjarry/aerc/refs/0.15.2) - 2023-05-11
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)
}()
diff --git a/doc/aerc.1.scd b/doc/aerc.1.scd
index 36b2f6bd..a4892b03 100644
--- a/doc/aerc.1.scd
+++ b/doc/aerc.1.scd
@@ -405,7 +405,9 @@ message list, the message in the message viewer, etc).
enabled.
*:export-mbox* _<file>_
- Exports all messages in the current folder to an mbox file.
+ Exports messages in the current folder to an mbox file. If there are marked
+ messages in the folder, only the marked ones are exported. Otherwise the
+ whole folder is exported.
*:import-mbox* _<file>_
Imports all messages from an mbox file to the current folder.