mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-21 15:17:01 +00:00
Introduce an "envelope" package
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).
This commit is contained in:
38
internal/envelope/envelope.go
Normal file
38
internal/envelope/envelope.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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)
|
||||
}
|
||||
Reference in New Issue
Block a user