diff options
author | Reto Brunner <reto@labrat.space> | 2020-11-10 19:57:09 +0100 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-11-14 15:40:13 +0100 |
commit | fc9ccc30008e564c1dea23b3bfe480ca5a10c070 (patch) | |
tree | 80acc77569557d73cbd073def0dabd6472653b5d /worker | |
parent | fb67d1f5a3f6fe875d74581aff59c79817a7b9f4 (diff) | |
download | aerc-fc9ccc30008e564c1dea23b3bfe480ca5a10c070.tar.gz |
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
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/imap.go | 7 | ||||
-rw-r--r-- | worker/lib/parse.go | 8 | ||||
-rw-r--r-- | worker/lib/sort.go | 13 |
3 files changed, 15 insertions, 13 deletions
diff --git a/worker/imap/imap.go b/worker/imap/imap.go index aa1854d..e296e9b 100644 --- a/worker/imap/imap.go +++ b/worker/imap/imap.go @@ -5,6 +5,7 @@ import ( "git.sr.ht/~sircmpwn/aerc/models" "github.com/emersion/go-message/charset" + "github.com/emersion/go-message/mail" ) func init() { @@ -59,10 +60,10 @@ func translateEnvelope(e *imap.Envelope) *models.Envelope { } } -func translateAddresses(addrs []*imap.Address) []*models.Address { - var converted []*models.Address +func translateAddresses(addrs []*imap.Address) []*mail.Address { + var converted []*mail.Address for _, addr := range addrs { - converted = append(converted, &models.Address{ + converted = append(converted, &mail.Address{ Name: addr.PersonalName, Address: addr.Address(), }) diff --git a/worker/lib/parse.go b/worker/lib/parse.go index edd3649..9fa539f 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -193,19 +193,19 @@ func parseReceivedHeader(h *mail.Header) (time.Time, error) { return time.Parse(time.RFC1123Z, dateRe.FindString(guess)) } -func parseAddressList(h *mail.Header, key string) ([]*models.Address, error) { - var converted []*models.Address +func parseAddressList(h *mail.Header, key string) ([]*mail.Address, error) { + var converted []*mail.Address addrs, err := h.AddressList(key) if err != nil { if hdr, err := h.Text(key); err == nil { - return []*models.Address{&models.Address{ + return []*mail.Address{&mail.Address{ Name: hdr, }}, nil } return nil, err } for _, addr := range addrs { - converted = append(converted, &models.Address{ + converted = append(converted, &mail.Address{ Name: addr.Name, Address: addr.Address, }) diff --git a/worker/lib/sort.go b/worker/lib/sort.go index 9d1f50a..09bcf77 100644 --- a/worker/lib/sort.go +++ b/worker/lib/sort.go @@ -6,6 +6,7 @@ import ( "git.sr.ht/~sircmpwn/aerc/models" "git.sr.ht/~sircmpwn/aerc/worker/types" + "github.com/emersion/go-message/mail" ) func Sort(messageInfos []*models.MessageInfo, @@ -20,7 +21,7 @@ func Sort(messageInfos []*models.MessageInfo, }) case types.SortCc: sortAddresses(messageInfos, criterion, - func(msgInfo *models.MessageInfo) []*models.Address { + func(msgInfo *models.MessageInfo) []*mail.Address { return msgInfo.Envelope.Cc }) case types.SortDate: @@ -29,7 +30,7 @@ func Sort(messageInfos []*models.MessageInfo, }) case types.SortFrom: sortAddresses(messageInfos, criterion, - func(msgInfo *models.MessageInfo) []*models.Address { + func(msgInfo *models.MessageInfo) []*mail.Address { return msgInfo.Envelope.From }) case types.SortRead: @@ -47,7 +48,7 @@ func Sort(messageInfos []*models.MessageInfo, }) case types.SortTo: sortAddresses(messageInfos, criterion, - func(msgInfo *models.MessageInfo) []*models.Address { + func(msgInfo *models.MessageInfo) []*mail.Address { return msgInfo.Envelope.To }) } @@ -61,10 +62,10 @@ func Sort(messageInfos []*models.MessageInfo, } func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCriterion, - getValue func(*models.MessageInfo) []*models.Address) { + getValue func(*models.MessageInfo) []*mail.Address) { sortSlice(criterion, messageInfos, func(i, j int) bool { addressI, addressJ := getValue(messageInfos[i]), getValue(messageInfos[j]) - var firstI, firstJ *models.Address + var firstI, firstJ *mail.Address if len(addressI) > 0 { firstI = addressI[0] } @@ -78,7 +79,7 @@ func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCrit } else if firstI != nil && firstJ == nil { return true } else /* firstI != nil && firstJ != nil */ { - getName := func(addr *models.Address) string { + getName := func(addr *mail.Address) string { if addr.Name != "" { return addr.Name } else { |