aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-11-10 20:35:47 +0100
committerReto Brunner <reto@labrat.space>2020-11-14 15:40:13 +0100
commit24f1c575ae7941fa4239ec60bd86aef2f6641364 (patch)
treeaaf355b590014fa4a6eb0a1ed16edbe9322948bd
parent20ec2c8eeb2e071f28358814935a0f56672a9f49 (diff)
downloadaerc-24f1c575ae7941fa4239ec60bd86aef2f6641364.tar.gz
format: remove parse methods, use the one from go-message
-rw-r--r--commands/compose/send.go3
-rw-r--r--commands/msg/reply.go11
-rw-r--r--lib/format/format.go33
3 files changed, 9 insertions, 38 deletions
diff --git a/commands/compose/send.go b/commands/compose/send.go
index 70446dab..e7ef5091 100644
--- a/commands/compose/send.go
+++ b/commands/compose/send.go
@@ -16,7 +16,6 @@ import (
"github.com/pkg/errors"
"git.sr.ht/~sircmpwn/aerc/lib"
- "git.sr.ht/~sircmpwn/aerc/lib/format"
"git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types"
@@ -84,7 +83,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
if config.From == "" {
return errors.New("No 'From' configured for this account")
}
- from, err := format.ParseAddress(config.From)
+ from, err := mail.ParseAddress(config.From)
if err != nil {
return errors.Wrap(err, "ParseAddress(config.From)")
}
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 863c7d25..fcd83419 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -61,13 +61,16 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("No account selected")
}
conf := acct.AccountConfig()
- from, err := format.ParseAddress(conf.From)
+ from, err := mail.ParseAddress(conf.From)
if err != nil {
return err
}
- aliases, err := format.ParseAddressList(conf.Aliases)
- if err != nil {
- return err
+ var aliases []*mail.Address
+ if conf.Aliases != "" {
+ aliases, err = mail.ParseAddressList(conf.Aliases)
+ if err != nil {
+ return err
+ }
}
store := widget.Store()
diff --git a/lib/format/format.go b/lib/format/format.go
index 2ba4d646..30e8be7f 100644
--- a/lib/format/format.go
+++ b/lib/format/format.go
@@ -3,46 +3,15 @@ package format
import (
"errors"
"fmt"
- "mime"
- gomail "net/mail"
"regexp"
"strings"
"time"
"unicode"
"git.sr.ht/~sircmpwn/aerc/models"
- "github.com/emersion/go-message"
"github.com/emersion/go-message/mail"
)
-func ParseAddress(address string) (*mail.Address, error) {
- addrs, err := gomail.ParseAddress(address)
- if err != nil {
- return nil, err
- }
- return (*mail.Address)(addrs), nil
-}
-
-func ParseAddressList(s string) ([]*mail.Address, error) {
- if len(s) == 0 {
- // we don't consider an empty list to be an error
- return nil, nil
- }
- parser := gomail.AddressParser{
- &mime.WordDecoder{message.CharsetReader},
- }
- list, err := parser.ParseList(s)
- if err != nil {
- return nil, err
- }
-
- addrs := make([]*mail.Address, len(list))
- for i, a := range list {
- addrs[i] = (*mail.Address)(a)
- }
- return addrs, nil
-}
-
// AddressForHumans 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.
@@ -83,7 +52,7 @@ func ParseMessageFormat(format string, timeFmt string, ctx Ctx) (string,
retval := make([]byte, 0, len(format))
var args []interface{}
- accountFromAddress, err := ParseAddress(ctx.FromAddress)
+ accountFromAddress, err := mail.ParseAddress(ctx.FromAddress)
if err != nil {
return "", nil, err
}