mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
This patch introduces an "envelope" package which, for now, provides simple utilities for getting the user and domain of an address. It also changes the couriers to use it (but other implementations remain, will be moved over in subsequent patches).
39 lines
702 B
Go
39 lines
702 B
Go
// Package envelope implements functions related to handling email envelopes
|
|
// (basically tuples of (from, to, data).
|
|
package envelope
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"blitiri.com.ar/go/chasquid/internal/set"
|
|
)
|
|
|
|
// Split an user@domain address into user and domain.
|
|
func split(addr string) (string, string) {
|
|
ps := strings.SplitN(addr, "@", 2)
|
|
if len(ps) != 2 {
|
|
return addr, ""
|
|
}
|
|
|
|
return ps[0], ps[1]
|
|
}
|
|
|
|
func UserOf(addr string) string {
|
|
user, _ := split(addr)
|
|
return user
|
|
}
|
|
|
|
func DomainOf(addr string) string {
|
|
_, domain := split(addr)
|
|
return domain
|
|
}
|
|
|
|
func DomainIn(addr string, locals *set.String) bool {
|
|
domain := DomainOf(addr)
|
|
if domain == "" {
|
|
return true
|
|
}
|
|
|
|
return locals.Has(domain)
|
|
}
|