aboutsummaryrefslogtreecommitdiffstats
path: root/app/compose.go
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2023-10-25 22:49:54 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-26 00:29:31 +0200
commit900d7da296f12081946666c82973f408d9d5f5aa (patch)
treec02687297a113250604e263362c8a0e8594ce6a1 /app/compose.go
parentf4166e07439fc08b3a632664a74ec6943b2050c7 (diff)
downloadaerc-900d7da296f12081946666c82973f408d9d5f5aa.tar.gz
compose: fix crash when getting hostname
Currently we assume that a From: address is present when retrieving the hostname for the message ID. This results in an index-out-of-range error when no From address is present. Generate a random hostname for the message ID, if no From: address is present. Fixes: 608bc4fa7fa7 ("compose: use email domain name in Message-Id") Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'app/compose.go')
-rw-r--r--app/compose.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/app/compose.go b/app/compose.go
index fdc993ed..101a5765 100644
--- a/app/compose.go
+++ b/app/compose.go
@@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"io"
+ "math/rand"
"net/textproto"
"os"
"os/exec"
@@ -921,6 +922,10 @@ func getMessageIdHostname(c *Composer) (string, error) {
if err != nil {
return "", err
}
+ if len(addrs) == 0 {
+ // no from address present, generate a random hostname
+ return strings.ToUpper(strconv.FormatInt(rand.Int63(), 36)), nil
+ }
_, domain, found := strings.Cut(addrs[0].Address, "@")
if !found {
return "", fmt.Errorf("Invalid address %q", addrs[0])