diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-05-16 10:49:50 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-05-16 10:49:50 -0400 |
commit | 2b3e123cb86f9b4c5853e31d9e76c2b0d083f90a (patch) | |
tree | 2845d2e611a4abd2e6561c31b522178176c75f82 /widgets/compose.go | |
parent | b0bf09b98fc038c1bc9921d568c06260b7448a15 (diff) |
Let caller pass in custom headers to compose
Diffstat (limited to 'widgets/compose.go')
-rw-r--r-- | widgets/compose.go | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/widgets/compose.go b/widgets/compose.go index 7f7afef..2359cad 100644 --- 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 } |