Handle MIME encoded addresses in address book
When addresses contain special characters, net/mail MIME-encodes them to a valid RFC 5322 address for use in headers. However, these are not pleasant for human consumption, so we decode them for use in the completion list. Aerc properly encodes addresses when the message is sent. This patch also removes surrounding white space from contact names, if present.
This commit is contained in:
parent
b360cca977
commit
0c9f59bad4
1 changed files with 12 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"mime"
|
||||
"net/mail"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -139,13 +140,22 @@ func readCompletions(r io.Reader) ([]string, error) {
|
|||
parts := strings.SplitN(line, "\t", 3)
|
||||
if addr, err := mail.ParseAddress(parts[0]); err == nil {
|
||||
if len(parts) > 1 {
|
||||
addr.Name = parts[1]
|
||||
addr.Name = strings.TrimSpace(parts[1])
|
||||
}
|
||||
completions = append(completions, addr.String())
|
||||
decoded, err := decodeMIME(addr.String())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not decode MIME string: %w", err)
|
||||
}
|
||||
completions = append(completions, decoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func decodeMIME(s string) (string, error) {
|
||||
var d mime.WordDecoder
|
||||
return d.DecodeHeader(s)
|
||||
}
|
||||
|
||||
func (c *Completer) handleErr(err error) {
|
||||
if c.errHandler != nil {
|
||||
c.errHandler(err)
|
||||
|
|
Loading…
Reference in a new issue