summaryrefslogtreecommitdiff
path: root/completer
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-12-30 09:41:32 -0500
committerDrew DeVault <sir@cmpwn.com>2019-12-30 15:31:16 -0500
commit0c9f59bad49d5b7073efd1acd7c0299a02b25509 (patch)
tree551faed07d2e5c4ba7dc08e5218878cbb9ada4d8 /completer
parentb360cca977bdf29d19764712d97af22e9165e2d0 (diff)
downloadaerc-0c9f59bad49d5b7073efd1acd7c0299a02b25509.zip
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.
Diffstat (limited to 'completer')
-rw-r--r--completer/completer.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/completer/completer.go b/completer/completer.go
index baa897d..f6900ee 100644
--- a/completer/completer.go
+++ b/completer/completer.go
@@ -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)