aboutsummaryrefslogtreecommitdiffstats
path: root/commands/compose
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-11-10 20:27:30 +0100
committerReto Brunner <reto@labrat.space>2020-11-14 15:40:13 +0100
commit20ec2c8eeb2e071f28358814935a0f56672a9f49 (patch)
tree501b43a39a4152872bb6f08221da9c37fc75559c /commands/compose
parent3ad3a5ede07c1248ae8176bdc19a623731c64056 (diff)
downloadaerc-20ec2c8eeb2e071f28358814935a0f56672a9f49.tar.gz
compose: use a proper header instead of a string map
Prior to this commit, the composer was based on a map[string]string. While this approach was very versatile, it lead to a constant encoding / decoding of addresses and other headers. This commit switches to a different model, where the composer is based on a header. Commands which want to interact with it can simply set some defaults they would like to have. Users can overwrite them however they like. In order to get access to the functions generating / getting the msgid go-message was upgraded.
Diffstat (limited to 'commands/compose')
-rw-r--r--commands/compose/header.go7
-rw-r--r--commands/compose/postpone.go2
-rw-r--r--commands/compose/send.go32
3 files changed, 32 insertions, 9 deletions
diff --git a/commands/compose/header.go b/commands/compose/header.go
index 5188a8a2..dd0adee9 100644
--- a/commands/compose/header.go
+++ b/commands/compose/header.go
@@ -57,18 +57,17 @@ func (Header) Execute(aerc *widgets.Aerc, args []string) error {
composer, _ := aerc.SelectedTab().(*widgets.Composer)
if !force {
- headers, _, err := composer.PrepareHeader()
+ headers, err := composer.PrepareHeader()
if err != nil {
return err
}
- if headers.Has(strings.Title(args[optind])) {
+ if headers.Has(args[optind]) {
return fmt.Errorf("Header %s already exists", args[optind])
}
}
- composer.AddEditor(strings.Title(args[optind]),
- strings.Join(args[optind+1:], " "), false)
+ composer.AddEditor(args[optind], strings.Join(args[optind+1:], " "), false)
return nil
}
diff --git a/commands/compose/postpone.go b/commands/compose/postpone.go
index 60c9df1a..365b683f 100644
--- a/commands/compose/postpone.go
+++ b/commands/compose/postpone.go
@@ -40,7 +40,7 @@ func (Postpone) Execute(aerc *widgets.Aerc, args []string) error {
aerc.Logger().Println("Postponing mail")
- header, _, err := composer.PrepareHeader()
+ header, err := composer.PrepareHeader()
if err != nil {
return errors.Wrap(err, "PrepareHeader")
}
diff --git a/commands/compose/send.go b/commands/compose/send.go
index abbcb544..70446dab 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -4,7 +4,6 @@ import (
"crypto/tls"
"fmt"
"io"
- "net/mail"
"net/url"
"os/exec"
"strings"
@@ -17,9 +16,11 @@ import (
"github.com/pkg/errors"
"git.sr.ht/~sircmpwn/aerc/lib"
+ "git.sr.ht/~sircmpwn/aerc/lib/format"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types"
+ "github.com/emersion/go-message/mail"
"golang.org/x/oauth2"
)
@@ -71,15 +72,19 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
}
}
- header, rcpts, err := composer.PrepareHeader()
+ header, err := composer.PrepareHeader()
if err != nil {
return errors.Wrap(err, "PrepareHeader")
}
+ rcpts, err := listRecipients(header)
+ if err != nil {
+ return errors.Wrap(err, "listRecipients")
+ }
if config.From == "" {
return errors.New("No 'From' configured for this account")
}
- from, err := mail.ParseAddress(config.From)
+ from, err := format.ParseAddress(config.From)
if err != nil {
return errors.Wrap(err, "ParseAddress(config.From)")
}
@@ -288,7 +293,12 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
composer.Close()
}
})
- header, _, _ := composer.PrepareHeader()
+ header, err := composer.PrepareHeader()
+ if err != nil {
+ aerc.PushError(" " + err.Error())
+ w.Close()
+ return
+ }
composer.WriteMessage(header, w)
w.Close()
} else {
@@ -299,3 +309,17 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
}()
return nil
}
+
+func listRecipients(h *mail.Header) ([]string, error) {
+ var rcpts []string
+ for _, key := range []string{"to", "cc", "bcc"} {
+ list, err := h.AddressList(key)
+ if err != nil {
+ return nil, err
+ }
+ for _, addr := range list {
+ rcpts = append(rcpts, addr.Address)
+ }
+ }
+ return rcpts, nil
+}