Add addresses argument to forward command

This commit is contained in:
Jelle Besseling 2019-08-18 11:33:14 +02:00 committed by Drew DeVault
parent 217e8855f2
commit 36c6030e81
3 changed files with 17 additions and 2 deletions

View file

@ -8,6 +8,7 @@ import (
"github.com/emersion/go-message" "github.com/emersion/go-message"
"github.com/emersion/go-message/mail" "github.com/emersion/go-message/mail"
"io" "io"
"strings"
) )
type forward struct{} type forward struct{}
@ -25,8 +26,9 @@ func (_ forward) Complete(aerc *widgets.Aerc, args []string) []string {
} }
func (_ forward) Execute(aerc *widgets.Aerc, args []string) error { func (_ forward) Execute(aerc *widgets.Aerc, args []string) error {
to := ""
if len(args) != 1 { if len(args) != 1 {
return errors.New("Usage: forward") to = strings.Join(args[1:], ", ")
} }
widget := aerc.SelectedTab().(widgets.ProvidesMessage) widget := aerc.SelectedTab().(widgets.ProvidesMessage)
@ -46,6 +48,7 @@ func (_ forward) Execute(aerc *widgets.Aerc, args []string) error {
subject := "Fwd: " + msg.Envelope.Subject subject := "Fwd: " + msg.Envelope.Subject
defaults := map[string]string{ defaults := map[string]string{
"To": to,
"Subject": subject, "Subject": subject,
} }
composer := widgets.NewComposer(aerc.Config(), acct.AccountConfig(), composer := widgets.NewComposer(aerc.Config(), acct.AccountConfig(),
@ -53,6 +56,11 @@ func (_ forward) Execute(aerc *widgets.Aerc, args []string) error {
addTab := func() { addTab := func() {
tab := aerc.NewTab(composer, subject) tab := aerc.NewTab(composer, subject)
if len(args) == 1 {
composer.FocusRecipient()
} else {
composer.FocusTerminal()
}
composer.OnHeaderChange("Subject", func(subject string) { composer.OnHeaderChange("Subject", func(subject string) {
if subject == "" { if subject == "" {
tab.Name = "New email" tab.Name = "New email"

View file

@ -90,7 +90,7 @@ message list, the message in the message viewer, etc).
*delete* *delete*
Deletes the selected message. Deletes the selected message.
*forward* *forward* [address...]
Opens the composer to forward the selected message to another recipient. Opens the composer to forward the selected message to another recipient.
*move* <target> *move* <target>

View file

@ -153,6 +153,13 @@ func (c *Composer) FocusSubject() *Composer {
return c return c
} }
func (c *Composer) FocusRecipient() *Composer {
c.focusable[c.focused].Focus(false)
c.focused = 1
c.focusable[c.focused].Focus(true)
return c
}
// OnHeaderChange registers an OnChange callback for the specified header. // OnHeaderChange registers an OnChange callback for the specified header.
func (c *Composer) OnHeaderChange(header string, fn func(subject string)) { func (c *Composer) OnHeaderChange(header string, fn func(subject string)) {
if editor, ok := c.editors[header]; ok { if editor, ok := c.editors[header]; ok {