aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKarel Balej <balejk@matfyz.cz>2024-01-30 20:11:28 +0100
committerRobin Jarry <robin@jarry.cc>2024-02-12 23:01:55 +0100
commite8a6e8316a4b6e923f75b1e9a2d06089033e480b (patch)
tree079385307b6428f4a70ebd0450febdb7715a2a99 /lib
parent3553e4f27165b18be84123d0ca015a019d35e41c (diff)
downloadaerc-e8a6e8316a4b6e923f75b1e9a2d06089033e480b.tar.gz
aerc-e8a6e8316a4b6e923f75b1e9a2d06089033e480b.zip
lib: add function to obtain Message-ID hostname
Make the function already present in app/compose.go reusable while also changing its signature for it not to require involvement of a Composer instance. Signed-off-by: Karel Balej <balejk@matfyz.cz> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/send/parse.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/send/parse.go b/lib/send/parse.go
index 460e91dc..d1088ee2 100644
--- a/lib/send/parse.go
+++ b/lib/send/parse.go
@@ -2,8 +2,13 @@ package send
import (
"fmt"
+ "math/rand"
"net/url"
+ "os"
+ "strconv"
"strings"
+
+ "github.com/emersion/go-message/mail"
)
func parseScheme(uri *url.URL) (protocol string, auth string, err error) {
@@ -30,3 +35,18 @@ func parseScheme(uri *url.URL) (protocol string, auth string, err error) {
}
return protocol, auth, nil
}
+
+func GetMessageIdHostname(sendWithHostname bool, from *mail.Address) (string, error) {
+ if sendWithHostname {
+ return os.Hostname()
+ }
+ if from == nil {
+ // no from address present, generate a random hostname
+ return strings.ToUpper(strconv.FormatInt(rand.Int63(), 36)), nil
+ }
+ _, domain, found := strings.Cut(from.Address, "@")
+ if !found {
+ return "", fmt.Errorf("Invalid address %q", from)
+ }
+ return domain, nil
+}