Add cc and bcc commands

This commit is contained in:
Daniel Bridges 2019-08-01 11:29:21 -07:00 committed by Drew DeVault
parent b72bb27cb4
commit f4b7741463
3 changed files with 87 additions and 14 deletions

View File

@ -0,0 +1,39 @@
package compose
import (
"fmt"
"strings"
"git.sr.ht/~sircmpwn/aerc/widgets"
)
type CC struct{}
func init() {
register(CC{})
}
func (_ CC) Aliases() []string {
return []string{"cc", "bcc"}
}
func (_ CC) Complete(aerc *widgets.Aerc, args []string) []string {
return nil
}
func (_ CC) Execute(aerc *widgets.Aerc, args []string) error {
if len(args) < 2 {
return fmt.Errorf("Usage: %s <addresses>", args[0])
}
addrs := strings.Join(args[1:], " ")
composer, _ := aerc.SelectedTab().(*widgets.Composer)
switch args[0] {
case "cc":
composer.AddEditor("Cc", addrs)
case "bcc":
composer.AddEditor("Bcc", addrs)
}
return nil
}

View File

@ -216,6 +216,10 @@ message list, the message in the message viewer, etc).
Detaches the file with the given path from the composed email. If no path is
specified, detaches the first attachment instead.
*cc* <addresses>, *bcc* <addresses>
Sets the Cc or Bcc header to the given addresses. If an editor for the header
is not currently visible in the compose window, a new one will be added.
*edit*
(Re-) opens your text editor to edit the message in progress.

View File

@ -34,9 +34,11 @@ type Composer struct {
email *os.File
attachments []string
grid *ui.Grid
header *ui.Grid
review *reviewMessage
worker *types.Worker
layout HeaderLayout
focusable []ui.DrawableInteractive
focused int
}
@ -54,38 +56,26 @@ func NewComposer(conf *config.AercConfig,
layout, editors, focusable := buildComposeHeader(
conf.Compose.HeaderLayout, defaults)
header, headerHeight := layout.grid(
func(header string) ui.Drawable { return editors[header] },
)
grid := ui.NewGrid().Rows([]ui.GridSpec{
{ui.SIZE_EXACT, headerHeight},
{ui.SIZE_WEIGHT, 1},
}).Columns([]ui.GridSpec{
{ui.SIZE_WEIGHT, 1},
})
email, err := ioutil.TempFile("", "aerc-compose-*.eml")
if err != nil {
// TODO: handle this better
return nil
}
grid.AddChild(header).At(0, 0)
c := &Composer{
editors: editors,
acct: acct,
config: conf,
defaults: defaults,
email: email,
grid: grid,
worker: worker,
layout: layout,
// You have to backtab to get to "From", since you usually don't edit it
focused: 1,
focusable: focusable,
}
c.updateGrid()
c.ShowTerminal()
return c
@ -518,6 +508,46 @@ func (c *Composer) NextField() {
c.focusable[c.focused].Focus(true)
}
// AddEditor appends a new header editor to the compose window.
func (c *Composer) AddEditor(header string, value string) {
if _, ok := c.editors[header]; ok {
c.editors[header].input.Set(value)
return
}
e := newHeaderEditor(header, value)
c.editors[header] = e
c.layout = append(c.layout, []string{header})
// Insert focus of new editor before terminal editor
c.focusable = append(
c.focusable[:len(c.focusable)-1],
e,
c.focusable[len(c.focusable)-1],
)
c.updateGrid()
}
// updateGrid should be called when the underlying header layout is changed.
func (c *Composer) updateGrid() {
header, height := c.layout.grid(
func(h string) ui.Drawable { return c.editors[h] },
)
if c.grid == nil {
c.grid = ui.NewGrid().Columns([]ui.GridSpec{{ui.SIZE_WEIGHT, 1}})
}
c.grid.Rows([]ui.GridSpec{
{ui.SIZE_EXACT, height},
{ui.SIZE_WEIGHT, 1},
})
if c.header != nil {
c.grid.RemoveChild(c.header)
}
c.header = header
c.grid.AddChild(c.header).At(0, 0)
}
func (c *Composer) reloadEmail() error {
name := c.email.Name()
c.email.Close()