about summary refs log tree commit diff stats
path: root/completer
diff options
context:
space:
mode:
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)