aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commands/account/copy.go38
-rw-r--r--commands/account/delete-message.go14
-rw-r--r--lib/msgstore.go18
-rw-r--r--widgets/account.go4
-rw-r--r--worker/imap/movecopy.go16
-rw-r--r--worker/imap/worker.go2
-rw-r--r--worker/types/messages.go12
7 files changed, 101 insertions, 3 deletions
diff --git a/commands/account/copy.go b/commands/account/copy.go
new file mode 100644
index 0000000..2a811c8
--- /dev/null
+++ b/commands/account/copy.go
@@ -0,0 +1,38 @@
+package account
+
+import (
+ "errors"
+ "time"
+
+ "github.com/gdamore/tcell"
+
+ "git.sr.ht/~sircmpwn/aerc2/widgets"
+ "git.sr.ht/~sircmpwn/aerc2/worker/types"
+)
+
+func init() {
+ register("cp", Copy)
+ register("copy", Copy)
+}
+
+func Copy(aerc *widgets.Aerc, args []string) error {
+ if len(args) != 2 {
+ return errors.New("Usage: mv <folder>")
+ }
+ acct := aerc.SelectedAccount()
+ if acct == nil {
+ return errors.New("No account selected")
+ }
+ msg := acct.Messages().Selected()
+ store := acct.Messages().Store()
+ store.Copy([]uint32{msg.Uid}, args[1], func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Done:
+ aerc.PushStatus("Messages copied.", 10*time.Second)
+ case *types.Error:
+ aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second).
+ Color(tcell.ColorDefault, tcell.ColorRed)
+ }
+ })
+ return nil
+}
diff --git a/commands/account/delete-message.go b/commands/account/delete-message.go
index 40e3bba..2461d64 100644
--- a/commands/account/delete-message.go
+++ b/commands/account/delete-message.go
@@ -2,8 +2,12 @@ package account
import (
"errors"
+ "time"
+
+ "github.com/gdamore/tcell"
"git.sr.ht/~sircmpwn/aerc2/widgets"
+ "git.sr.ht/~sircmpwn/aerc2/worker/types"
)
func init() {
@@ -20,6 +24,14 @@ func DeleteMessage(aerc *widgets.Aerc, args []string) error {
}
store := acct.Messages().Store()
msg := acct.Messages().Selected()
- store.Delete([]uint32{msg.Uid})
+ store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) {
+ switch msg := msg.(type) {
+ case *types.Done:
+ aerc.PushStatus("Messages deleted.", 10*time.Second)
+ case *types.Error:
+ aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second).
+ Color(tcell.ColorDefault, tcell.ColorRed)
+ }
+ })
return nil
}
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 32edfc5..c4f5326 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -218,7 +218,8 @@ func (store *MessageStore) update() {
}
}
-func (store *MessageStore) Delete(uids []uint32) {
+func (store *MessageStore) Delete(uids []uint32,
+ cb func(msg types.WorkerMessage)) {
store.Lock()
var set imap.SeqSet
@@ -229,6 +230,19 @@ func (store *MessageStore) Delete(uids []uint32) {
store.Unlock()
- store.worker.PostAction(&types.DeleteMessages{Uids: set}, nil)
+ store.worker.PostAction(&types.DeleteMessages{Uids: set}, cb)
store.update()
}
+
+func (store *MessageStore) Copy(uids []uint32, dest string,
+ cb func(msg types.WorkerMessage)) {
+ var set imap.SeqSet
+ for _, uid := range uids {
+ set.AddNum(uid)
+ }
+
+ store.worker.PostAction(&types.CopyMessages{
+ Destination: dest,
+ Uids: set,
+ }, cb)
+}
diff --git a/widgets/account.go b/widgets/account.go
index ba2b8d3..c252e38 100644
--- a/widgets/account.go
+++ b/widgets/account.go
@@ -110,6 +110,10 @@ func (acct *AccountView) Focus(focus bool) {
// TODO: Unfocus children I guess
}
+func (acct *AccountView) Worker() *types.Worker {
+ return acct.worker
+}
+
func (acct *AccountView) connected(msg types.WorkerMessage) {
switch msg := msg.(type) {
case *types.Done:
diff --git a/worker/imap/movecopy.go b/worker/imap/movecopy.go
new file mode 100644
index 0000000..8c42a2e
--- /dev/null
+++ b/worker/imap/movecopy.go
@@ -0,0 +1,16 @@
+package imap
+
+import (
+ "git.sr.ht/~sircmpwn/aerc2/worker/types"
+)
+
+func (imapw *IMAPWorker) handleCopyMessages(msg *types.CopyMessages) {
+ if err := imapw.client.UidCopy(&msg.Uids, msg.Destination); err != nil {
+ imapw.worker.PostMessage(&types.Error{
+ Message: types.RespondTo(msg),
+ Error: err,
+ }, nil)
+ } else {
+ imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
+ }
+}
diff --git a/worker/imap/worker.go b/worker/imap/worker.go
index d0b0e71..1fab3bb 100644
--- a/worker/imap/worker.go
+++ b/worker/imap/worker.go
@@ -174,6 +174,8 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
w.handleFetchFullMessages(msg)
case *types.DeleteMessages:
w.handleDeleteMessages(msg)
+ case *types.CopyMessages:
+ w.handleCopyMessages(msg)
default:
return errUnsupported
}
diff --git a/worker/types/messages.go b/worker/types/messages.go
index b17d53d..fdd3263 100644
--- a/worker/types/messages.go
+++ b/worker/types/messages.go
@@ -97,6 +97,18 @@ type DeleteMessages struct {
Uids imap.SeqSet
}
+type CopyMessages struct {
+ Message
+ Destination string
+ Uids imap.SeqSet
+}
+
+type MoveMessages struct {
+ Message
+ Destination string
+ Uids imap.SeqSet
+}
+
// Messages
type CertificateApprovalRequest struct {