1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 18:17:03 +00:00
A couple email address related utils
This commit is contained in:
James Hillyerd
2012-10-06 20:35:33 -07:00
parent be97a4528f
commit ff3a4264cf
3 changed files with 62 additions and 0 deletions

28
app/inbucket/utils.go Normal file
View File

@@ -0,0 +1,28 @@
package inbucket
import (
"crypto/sha1"
"fmt"
"io"
"strings"
)
// Take "user+ext@host.com" and return "user", aka the mailbox we'll store it in
func ParseMailboxName(emailAddress string) (result string) {
result = strings.ToLower(emailAddress)
if idx := strings.Index(result, "@"); idx > -1 {
result = result[0:idx]
}
if idx := strings.Index(result, "+"); idx > -1 {
result = result[0:idx]
}
return result
}
// Take a mailbox name and hash it into the directory we'll store it in
func HashMailboxName(mailbox string) string {
h := sha1.New()
io.WriteString(h, mailbox)
return fmt.Sprintf("%x", h.Sum(nil))
}