Debian Codegraph @

lib/send/parse.go

raw
1 package send
2
3 import (
4 "fmt"
5 "math/rand"
6 "os"
7 "strconv"
8 "strings"
9
10 "github.com/emersion/go-message/mail"
11 )
12
13 func GetMessageIdHostname(sendWithHostname bool, from *mail.Address) (string, error) {
14 if sendWithHostname {
15 return os.Hostname()
16 }
17 if from == nil {
18 // no from address present, generate a random hostname
19 return strings.ToUpper(strconv.FormatInt(rand.Int63(), 36)), nil
20 }
21 _, domain, found := strings.Cut(from.Address, "@")
22 if !found {
23 return "", fmt.Errorf("Invalid address %q", from)
24 }
25 return domain, nil
26 }