aerc

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

commit 2b3e123cb86f9b4c5853e31d9e76c2b0d083f90a
parent b0bf09b98fc038c1bc9921d568c06260b7448a15
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 16 May 2019 10:49:50 -0400

Let caller pass in custom headers to compose

Diffstat:
Mcommands/compose/send.go | 4++--
Mlib/ui/textinput.go | 4++++
Mwidgets/compose.go | 38++++++++++++++++++++++++++++++++------
3 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/commands/compose/send.go b/commands/compose/send.go @@ -53,7 +53,7 @@ func SendMessage(aerc *widgets.Aerc, args []string) error { return fmt.Errorf("Unknown transfer protocol %s", uri.Scheme) } - header, rcpts, err := composer.Header() + header, rcpts, err := composer.PrepareHeader() if err != nil { return err } @@ -188,7 +188,7 @@ func SendMessage(aerc *widgets.Aerc, args []string) error { composer.Close() } }) - header, _, _ := composer.Header() + header, _, _ := composer.PrepareHeader() composer.WriteMessage(header, w) w.Close() } else { diff --git a/lib/ui/textinput.go b/lib/ui/textinput.go @@ -40,6 +40,10 @@ func (ti *TextInput) String() string { return string(ti.text) } +func (ti *TextInput) Set(value string) { + ti.text = []rune(value) +} + func (ti *TextInput) Invalidate() { ti.DoInvalidate(ti) } diff --git a/widgets/compose.go b/widgets/compose.go @@ -27,11 +27,12 @@ type Composer struct { config *config.AccountConfig - editor *Terminal - email *os.File - grid *ui.Grid - review *reviewMessage - worker *types.Worker + defaults map[string]string + editor *Terminal + email *os.File + grid *ui.Grid + review *reviewMessage + worker *types.Worker focusable []ui.DrawableInteractive focused int @@ -104,6 +105,24 @@ func NewComposer(conf *config.AercConfig, return c } +// Sets additional headers to be added to the outgoing email (e.g. In-Reply-To) +func (c *Composer) Defaults(defaults map[string]string) *Composer { + c.defaults = defaults + if to, ok := defaults["To"]; ok { + c.headers.to.input.Set(to) + delete(defaults, "To") + } + if from, ok := defaults["From"]; ok { + c.headers.from.input.Set(from) + delete(defaults, "From") + } + if subject, ok := defaults["Subject"]; ok { + c.headers.subject.input.Set(subject) + delete(defaults, "Subject") + } + return c +} + func (c *Composer) OnSubjectChange(fn func(subject string)) { c.headers.subject.OnChange(func() { fn(c.headers.subject.input.String()) @@ -163,7 +182,7 @@ func (c *Composer) Worker() *types.Worker { return c.worker } -func (c *Composer) Header() (*mail.Header, []string, error) { +func (c *Composer) PrepareHeader() (*mail.Header, []string, error) { // Extract headers from the email, if present c.email.Seek(0, os.SEEK_SET) var ( @@ -209,6 +228,13 @@ func (c *Composer) Header() (*mail.Header, []string, error) { rcpts = append(rcpts, addr.Address) } } + // Merge in additional headers + txthdr := mhdr.Header + for key, value := range c.defaults { + if !txthdr.Has(key) { + mhdr.SetText(key, value) + } + } // TODO: Add cc, bcc to rcpts return &header, rcpts, nil }