aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/compose.go
diff options
context:
space:
mode:
authorAdnan Maolood <adnan@maolood.com>2023-08-27 13:47:24 -0400
committerRobin Jarry <robin@jarry.cc>2023-08-28 11:56:23 +0200
commit608bc4fa7fa721ca1bef79e8d8a4630cd6124843 (patch)
treed483216634b2c0ac505de7b2e9359e0fc6aeb2d5 /widgets/compose.go
parenta5bc7ccf0cae608ac1e72ab4c9ebe5596eb8c988 (diff)
downloadaerc-608bc4fa7fa721ca1bef79e8d8a4630cd6124843.tar.gz
compose: use email domain name in Message-Id
RFC 5322 recommends using a domain name on the right-hand side of the "@" in Message-Ids. Since the local host domain name cannot be obtained reliably, use the sender email domain name by default. Add a new configuration option to maintain the old behavior. Link: https://www.rfc-editor.org/rfc/rfc5322.html#section-3.6.4 Signed-off-by: Adnan Maolood <adnan@maolood.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets/compose.go')
-rw-r--r--widgets/compose.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/widgets/compose.go b/widgets/compose.go
index f682fe5c..05d06a7f 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -136,6 +136,7 @@ func (c *Composer) SwitchAccount(newAcct *AccountView) error {
}
// ensure that from header is updated, so remove it
c.header.Del("from")
+ c.header.Del("message-id")
// update entire composer with new the account
if err := c.setupFor(newAcct); err != nil {
return err
@@ -845,10 +846,13 @@ func (c *Composer) PrepareHeader() (*mail.Header, error) {
// control headers not normally set by the user
// repeated calls to PrepareHeader should be a noop
if !c.header.Has("Message-Id") {
- err := c.header.GenerateMessageID()
+ hostname, err := getMessageIdHostname(c)
if err != nil {
return nil, err
}
+ if err := c.header.GenerateMessageIDWithHostname(hostname); err != nil {
+ return nil, err
+ }
}
// update the "Date" header every time PrepareHeader is called
@@ -861,6 +865,21 @@ func (c *Composer) PrepareHeader() (*mail.Header, error) {
return c.header, nil
}
+func getMessageIdHostname(c *Composer) (string, error) {
+ if c.acctConfig.SendWithHostname {
+ return os.Hostname()
+ }
+ addrs, err := c.header.AddressList("from")
+ if err != nil {
+ return "", err
+ }
+ _, domain, found := strings.Cut(addrs[0].Address, "@")
+ if !found {
+ return "", fmt.Errorf("Invalid address %q", addrs[0])
+ }
+ return domain, nil
+}
+
func (c *Composer) parseEmbeddedHeader() (*mail.Header, error) {
_, err := c.email.Seek(0, io.SeekStart)
if err != nil {
@@ -1531,6 +1550,9 @@ func (he *headerEditor) storeValue() {
default:
he.header.SetText(he.name, val)
}
+ if strings.ToLower(he.name) == "from" {
+ he.header.Del("message-id")
+ }
}
func (he *headerEditor) Draw(ctx *ui.Context) {