~sircmpwn/aerc

aerc: commands/msg: add trash command v1 PROPOSED

~sbinet
~sbinet: 2
 commands/msg: add trash command
 config: add bindings to trash messages

 2 files changed, 86 insertions(+), 1 deletions(-)
#579799 .build.yml success
builds.sr.ht
aerc/patches/.build.yml: SUCCESS in 55s

[commands/msg: add trash command][0] from [~sbinet][1]

[0]: https://lists.sr.ht/~sircmpwn/aerc/patches/24920
[1]: mailto:s@sbinet.org

✓ #579799 SUCCESS aerc/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/579799
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/aerc/patches/24920/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH aerc 1/2] commands/msg: add trash command Export this patch

~sbinet
From: Sebastien Binet <s@sbinet.org>

Signed-off-by: Sebastien Binet <s@sbinet.org>
---
 commands/msg/trash.go | 84 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 commands/msg/trash.go

diff --git a/commands/msg/trash.go b/commands/msg/trash.go
new file mode 100644
index 0000000..05aff49
--- /dev/null
+++ b/commands/msg/trash.go
@@ -0,0 +1,84 @@
package msg

import (
	"errors"
	"time"

	"git.sr.ht/~sircmpwn/aerc/lib"
	"git.sr.ht/~sircmpwn/aerc/widgets"
	"git.sr.ht/~sircmpwn/aerc/worker/types"
)

type Trash struct{}

func init() {
	register(Trash{})
}

func (Trash) Aliases() []string {
	return []string{"trash", "trash-message"}
}

func (Trash) Complete(aerc *widgets.Aerc, args []string) []string {
	return nil
}

func (Trash) Execute(aerc *widgets.Aerc, args []string) error {
	if len(args) != 1 {
		return errors.New("Usage: :trash")
	}

	h := newHelper(aerc)
	store, err := h.store()
	if err != nil {
		return err
	}
	uids, err := h.markedOrSelectedUids()
	if err != nil {
		return err
	}
	acct, err := h.account()
	if err != nil {
		return err
	}
	const createParents = false
	store.Move(uids, "Trash", createParents, func(msg types.WorkerMessage) {
		switch msg := msg.(type) {
		case *types.Done:
			aerc.PushStatus("Messages deleted.", 10*time.Second)
		case *types.Error:
			aerc.PushError(msg.Error.Error())
		case *types.Unsupported:
			// notmuch doesn't support it, we want the user to know
			aerc.PushError(" error, unsupported for this worker")
		}
	})

	//caution, can be nil
	next := findNextNonDeleted(uids, store)

	mv, isMsgView := h.msgProvider.(*widgets.MessageViewer)
	if isMsgView {
		if !aerc.Config().Ui.NextMessageOnDelete {
			aerc.RemoveTab(h.msgProvider)
		} else {
			// no more messages in the list
			if next == nil {
				aerc.RemoveTab(h.msgProvider)
				acct.Messages().Invalidate()
				return nil
			}
			lib.NewMessageStoreView(next, store, aerc.DecryptKeys,
				func(view lib.MessageView, err error) {
					if err != nil {
						aerc.PushError(err.Error())
						return
					}
					nextMv := widgets.NewMessageViewer(acct, aerc.Config(), view)
					aerc.ReplaceTab(mv, nextMv, next.Envelope.Subject)
				})
		}
	}
	acct.Messages().Invalidate()
	return nil
}
-- 
2.32.0
> + case *types.Done:
> +     aerc.PushStatus("Messages deleted.", 10*time.Second)
To me this sounds misleading. After all the whole point is not deleting
the message (right away)
> + case *types.Error:

[PATCH aerc 2/2] config: add bindings to trash messages Export this patch

~sbinet
From: Sebastien Binet <s@sbinet.org>

Signed-off-by: Sebastien Binet <s@sbinet.org>
---
 config/binds.conf | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/config/binds.conf b/config/binds.conf
index abfd77e..146d813 100644
--- a/config/binds.conf
+++ b/config/binds.conf
@@ -29,7 +29,7 @@ v = :mark -t<Enter>
V = :mark -v<Enter>

<Enter> = :view<Enter>
d = :prompt 'Really delete this message?' 'delete-message'<Enter>
d = :trash<Enter>
D = :delete<Enter>
A = :archive flat<Enter>

@@ -53,6 +53,7 @@ N = :prev-result<Enter>
[view]
q = :close<Enter>
| = :pipe<space>
d = :trash<Enter>
D = :delete<Enter>
S = :save<space>
A = :archive flat<Enter>
-- 
2.32.0
builds.sr.ht
aerc/patches/.build.yml: SUCCESS in 55s

[commands/msg: add trash command][0] from [~sbinet][1]

[0]: https://lists.sr.ht/~sircmpwn/aerc/patches/24920
[1]: mailto:s@sbinet.org

✓ #579799 SUCCESS aerc/patches/.build.yml https://builds.sr.ht/~sircmpwn/job/579799