aboutsummaryrefslogtreecommitdiffstats
path: root/lib/send/parse.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/send/parse.go')
-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
+}