1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00
Files
go-inbucket/pkg/stringutil/utils.go
James Hillyerd a7d2b00a9c policy: Implement recipient domain policy for #51
- INBUCKET_SMTP_DEFAULTACCEPT
- INBUCKET_SMTP_ACCEPTDOMAINS
- INBUCKET_SMTP_REJECTDOMAINS
2018-04-01 18:05:21 -07:00

49 lines
1002 B
Go

package stringutil
import (
"crypto/sha1"
"fmt"
"io"
"net/mail"
"strings"
)
// HashMailboxName accepts a mailbox name and hashes it. filestore uses this as
// the directory to house the mailbox
func HashMailboxName(mailbox string) string {
h := sha1.New()
if _, err := io.WriteString(h, mailbox); err != nil {
// This shouldn't ever happen
return ""
}
return fmt.Sprintf("%x", h.Sum(nil))
}
// StringAddressList converts a list of addresses to a list of strings
func StringAddressList(addrs []*mail.Address) []string {
s := make([]string, len(addrs))
for i, a := range addrs {
if a != nil {
s[i] = a.String()
}
}
return s
}
// SliceContains returns true if s is present in slice.
func SliceContains(slice []string, s string) bool {
for _, v := range slice {
if s == v {
return true
}
}
return false
}
// SliceToLower lowercases the contents of slice of strings.
func SliceToLower(slice []string) {
for i, s := range slice {
slice[i] = strings.ToLower(s)
}
}