aboutsummaryrefslogtreecommitdiffstats
path: root/commands/compose/send.go
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/send.go
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/send.go')
-rw-r--r--commands/compose/send.go32
1 files changed, 28 insertions, 4 deletions
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
+}