aerc

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

delete.go (1017B)


      1 package msg
      2 
      3 import (
      4 	"errors"
      5 	"time"
      6 
      7 	"github.com/gdamore/tcell"
      8 
      9 	"git.sr.ht/~sircmpwn/aerc/widgets"
     10 	"git.sr.ht/~sircmpwn/aerc/worker/types"
     11 )
     12 
     13 func init() {
     14 	register("delete", DeleteMessage)
     15 	register("delete-message", DeleteMessage)
     16 }
     17 
     18 func DeleteMessage(aerc *widgets.Aerc, args []string) error {
     19 	if len(args) != 1 {
     20 		return errors.New("Usage: :delete")
     21 	}
     22 
     23 	widget := aerc.SelectedTab().(widgets.ProvidesMessage)
     24 	acct := widget.SelectedAccount()
     25 	if acct == nil {
     26 		return errors.New("No account selected")
     27 	}
     28 	store := widget.Store()
     29 	msg := widget.SelectedMessage()
     30 	_, isMsgView := widget.(*widgets.MessageViewer)
     31 	if isMsgView {
     32 		aerc.RemoveTab(widget)
     33 	}
     34 	acct.Messages().Next()
     35 	store.Delete([]uint32{msg.Uid}, func(msg types.WorkerMessage) {
     36 		switch msg := msg.(type) {
     37 		case *types.Done:
     38 			aerc.PushStatus("Messages deleted.", 10*time.Second)
     39 		case *types.Error:
     40 			aerc.PushStatus(" "+msg.Error.Error(), 10*time.Second).
     41 				Color(tcell.ColorDefault, tcell.ColorRed)
     42 		}
     43 	})
     44 	return nil
     45 }