From b46b497f99d7f4dcba8936ce0ebfe8cf982cec1f Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Thu, 4 Jul 2019 22:34:52 -0400 Subject: Factor UI models out of the worker message package Before, the information needed to display different parts of the UI was tightly coupled to the specific messages being sent back and forth to the backend worker. Separating out a models package allows us to be more specific about exactly what a backend is able to and required to provide for the UI. --- lib/address.go | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 lib/address.go (limited to 'lib/address.go') diff --git a/lib/address.go b/lib/address.go deleted file mode 100644 index b557195..0000000 --- a/lib/address.go +++ /dev/null @@ -1,40 +0,0 @@ -package lib - -import ( - "bytes" - "fmt" - "regexp" - "strings" - - "github.com/emersion/go-imap" -) - -var ( - atom *regexp.Regexp = regexp.MustCompile("^[a-z0-9!#$%7'*+-/=?^_`{}|~ ]+$") -) - -func FormatAddresses(addrs []*imap.Address) string { - val := bytes.Buffer{} - for i, addr := range addrs { - val.WriteString(FormatAddress(addr)) - if i != len(addrs)-1 { - val.WriteString(", ") - } - } - return val.String() -} - -func FormatAddress(addr *imap.Address) string { - if addr.PersonalName != "" { - if atom.MatchString(addr.PersonalName) { - return fmt.Sprintf("%s <%s@%s>", - addr.PersonalName, addr.MailboxName, addr.HostName) - } else { - return fmt.Sprintf("\"%s\" <%s@%s>", - strings.ReplaceAll(addr.PersonalName, "\"", "'"), - addr.MailboxName, addr.HostName) - } - } else { - return fmt.Sprintf("<%s@%s>", addr.MailboxName, addr.HostName) - } -} -- cgit v1.2.3