1
0
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:
Alberto Bertogli
2016-07-19 23:18:40 +01:00
parent 831ef13132
commit 362ef6f6d0
6 changed files with 97 additions and 28 deletions

View 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)
}