aerc

Working clone of aerc-mail.org
git clone git://git.danielmoch.com/aerc.git
Log | Files | Refs | README | LICENSE

commit db213fd0aed98a79ecb1be2c7b7d61c7d983bedf
parent b0b3287bbdadad47757f3543a6560494af9175a8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 14 May 2019 16:34:42 -0400

Implement :copy (aka :cp)

Diffstat:
Acommands/account/copy.go | 38++++++++++++++++++++++++++++++++++++++
Mcommands/account/delete-message.go | 14+++++++++++++-
Mlib/msgstore.go | 18++++++++++++++++--
Mwidgets/account.go | 4++++
Aworker/imap/movecopy.go | 16++++++++++++++++
Mworker/imap/worker.go | 2++
Mworker/types/messages.go | 12++++++++++++
7 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/commands/account/copy.go 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 {