aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-05-16 10:49:50 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-16 10:49:50 -0400
commit2b3e123cb86f9b4c5853e31d9e76c2b0d083f90a (patch)
tree2845d2e611a4abd2e6561c31b522178176c75f82
parentb0bf09b98fc038c1bc9921d568c06260b7448a15 (diff)
Let caller pass in custom headers to compose
-rw-r--r--commands/compose/send.go4
-rw-r--r--lib/ui/textinput.go4
-rw-r--r--widgets/compose.go38
3 files changed, 38 insertions, 8 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go
index f9946b7..e1d6b1e 100644
--- 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
index 9d2cdc7..4a5308e 100644
--- 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
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
}