From fc9ccc30008e564c1dea23b3bfe480ca5a10c070 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Tue, 10 Nov 2020 19:57:09 +0100 Subject: remove models.Address in favor of go-message Address We made a new type out of go-message/mail.Address without any real reason. This suddenly made it necessary to convert from one to the other without actually having any benefit whatsoever. This commit gets rid of the additional type --- models/models.go | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) (limited to 'models') diff --git a/models/models.go b/models/models.go index a93db72..bfe0ff3 100644 --- a/models/models.go +++ b/models/models.go @@ -3,9 +3,6 @@ package models import ( "fmt" "io" - gomail "net/mail" - "regexp" - "strings" "time" "github.com/emersion/go-message/mail" @@ -127,34 +124,14 @@ func (bs *BodyStructure) PartAtIndex(index []int) (*BodyStructure, error) { type Envelope struct { Date time.Time Subject string - From []*Address - ReplyTo []*Address - To []*Address - Cc []*Address - Bcc []*Address + From []*mail.Address + ReplyTo []*mail.Address + To []*mail.Address + Cc []*mail.Address + Bcc []*mail.Address MessageId string } -type Address gomail.Address - -var atom *regexp.Regexp = regexp.MustCompile("^[a-z0-9!#$%7'*+-/=?^_`{}|~ ]+$") - -// String formats the address. If the address's name -// contains non-ASCII characters it will be quoted but not encoded. -// Meant for display purposes to the humans, not for sending over the wire. -func (a *Address) Format() string { - if a.Name != "" { - if atom.MatchString(a.Name) { - return fmt.Sprintf("%s <%s>", a.Name, a.Address) - } else { - return fmt.Sprintf("\"%s\" <%s>", - strings.ReplaceAll(a.Name, "\"", "'"), a.Address) - } - } else { - return fmt.Sprintf("<%s>", a.Address) - } -} - // OriginalMail is helper struct used for reply/forward type OriginalMail struct { Date time.Time -- cgit v1.2.3