format: remove parse methods, use the one from go-message

This commit is contained in:
Reto Brunner 2020-11-10 20:35:47 +01:00
parent 20ec2c8eeb
commit 24f1c575ae
3 changed files with 9 additions and 38 deletions

View file

@ -16,7 +16,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"git.sr.ht/~sircmpwn/aerc/lib" "git.sr.ht/~sircmpwn/aerc/lib"
"git.sr.ht/~sircmpwn/aerc/lib/format"
"git.sr.ht/~sircmpwn/aerc/models" "git.sr.ht/~sircmpwn/aerc/models"
"git.sr.ht/~sircmpwn/aerc/widgets" "git.sr.ht/~sircmpwn/aerc/widgets"
"git.sr.ht/~sircmpwn/aerc/worker/types" "git.sr.ht/~sircmpwn/aerc/worker/types"
@ -84,7 +83,7 @@ func (Send) Execute(aerc *widgets.Aerc, args []string) error {
if config.From == "" { if config.From == "" {
return errors.New("No 'From' configured for this account") return errors.New("No 'From' configured for this account")
} }
from, err := format.ParseAddress(config.From) from, err := mail.ParseAddress(config.From)
if err != nil { if err != nil {
return errors.Wrap(err, "ParseAddress(config.From)") return errors.Wrap(err, "ParseAddress(config.From)")
} }

View file

@ -61,14 +61,17 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
return errors.New("No account selected") return errors.New("No account selected")
} }
conf := acct.AccountConfig() conf := acct.AccountConfig()
from, err := format.ParseAddress(conf.From) from, err := mail.ParseAddress(conf.From)
if err != nil { if err != nil {
return err return err
} }
aliases, err := format.ParseAddressList(conf.Aliases) var aliases []*mail.Address
if conf.Aliases != "" {
aliases, err = mail.ParseAddressList(conf.Aliases)
if err != nil { if err != nil {
return err return err
} }
}
store := widget.Store() store := widget.Store()
if store == nil { if store == nil {

View file

@ -3,46 +3,15 @@ package format
import ( import (
"errors" "errors"
"fmt" "fmt"
"mime"
gomail "net/mail"
"regexp" "regexp"
"strings" "strings"
"time" "time"
"unicode" "unicode"
"git.sr.ht/~sircmpwn/aerc/models" "git.sr.ht/~sircmpwn/aerc/models"
"github.com/emersion/go-message"
"github.com/emersion/go-message/mail" "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 // AddressForHumans formats the address. If the address's name
// contains non-ASCII characters it will be quoted but not encoded. // contains non-ASCII characters it will be quoted but not encoded.
// Meant for display purposes to the humans, not for sending over the wire. // 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)) retval := make([]byte, 0, len(format))
var args []interface{} var args []interface{}
accountFromAddress, err := ParseAddress(ctx.FromAddress) accountFromAddress, err := mail.ParseAddress(ctx.FromAddress)
if err != nil { if err != nil {
return "", nil, err return "", nil, err
} }