Add cc and bcc commands
This commit is contained in:
parent
b72bb27cb4
commit
f4b7741463
|
@ -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
|
||||||
|
}
|
|
@ -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
|
Detaches the file with the given path from the composed email. If no path is
|
||||||
specified, detaches the first attachment instead.
|
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*
|
*edit*
|
||||||
(Re-) opens your text editor to edit the message in progress.
|
(Re-) opens your text editor to edit the message in progress.
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,11 @@ type Composer struct {
|
||||||
email *os.File
|
email *os.File
|
||||||
attachments []string
|
attachments []string
|
||||||
grid *ui.Grid
|
grid *ui.Grid
|
||||||
|
header *ui.Grid
|
||||||
review *reviewMessage
|
review *reviewMessage
|
||||||
worker *types.Worker
|
worker *types.Worker
|
||||||
|
|
||||||
|
layout HeaderLayout
|
||||||
focusable []ui.DrawableInteractive
|
focusable []ui.DrawableInteractive
|
||||||
focused int
|
focused int
|
||||||
}
|
}
|
||||||
|
@ -54,38 +56,26 @@ func NewComposer(conf *config.AercConfig,
|
||||||
layout, editors, focusable := buildComposeHeader(
|
layout, editors, focusable := buildComposeHeader(
|
||||||
conf.Compose.HeaderLayout, defaults)
|
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")
|
email, err := ioutil.TempFile("", "aerc-compose-*.eml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: handle this better
|
// TODO: handle this better
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
grid.AddChild(header).At(0, 0)
|
|
||||||
|
|
||||||
c := &Composer{
|
c := &Composer{
|
||||||
editors: editors,
|
editors: editors,
|
||||||
acct: acct,
|
acct: acct,
|
||||||
config: conf,
|
config: conf,
|
||||||
defaults: defaults,
|
defaults: defaults,
|
||||||
email: email,
|
email: email,
|
||||||
grid: grid,
|
|
||||||
worker: worker,
|
worker: worker,
|
||||||
|
layout: layout,
|
||||||
// You have to backtab to get to "From", since you usually don't edit it
|
// You have to backtab to get to "From", since you usually don't edit it
|
||||||
focused: 1,
|
focused: 1,
|
||||||
focusable: focusable,
|
focusable: focusable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.updateGrid()
|
||||||
c.ShowTerminal()
|
c.ShowTerminal()
|
||||||
|
|
||||||
return c
|
return c
|
||||||
|
@ -518,6 +508,46 @@ func (c *Composer) NextField() {
|
||||||
c.focusable[c.focused].Focus(true)
|
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 {
|
func (c *Composer) reloadEmail() error {
|
||||||
name := c.email.Name()
|
name := c.email.Name()
|
||||||
c.email.Close()
|
c.email.Close()
|
||||||
|
|
Loading…
Reference in New Issue