summary refs log tree commit diff stats
path: root/worker
diff options
context:
space:
mode:
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/imap.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/worker/imap/imap.go b/worker/imap/imap.go
index 06bcd00..b0aacf6 100644
--- a/worker/imap/imap.go
+++ b/worker/imap/imap.go
@@ -4,6 +4,7 @@ import (
 	"github.com/emersion/go-imap"
 
 	"git.sr.ht/~sircmpwn/aerc/models"
+	"github.com/emersion/go-message/charset"
 )
 
 func toSeqSet(uids []uint32) *imap.SeqSet {
@@ -22,15 +23,30 @@ func translateBodyStructure(bs *imap.BodyStructure) *models.BodyStructure {
 	for _, part := range bs.Parts {
 		parts = append(parts, translateBodyStructure(part))
 	}
+
+	// we need to decode, because imap store do not use MessageInfo()
+	// which do it via go-message
+	desc, _ := charset.DecodeHeader(bs.Description)
+	params := map[string]string{}
+	for k, v := range bs.Params {
+		params[k], _ = charset.DecodeHeader(v)
+	}
+	dispParams := map[string]string{}
+	for k, v := range bs.DispositionParams {
+		dispParams[k], _ = charset.DecodeHeader(v)
+	}
+
+	// TODO: is that all?
+
 	return &models.BodyStructure{
 		MIMEType:          bs.MIMEType,
 		MIMESubType:       bs.MIMESubType,
-		Params:            bs.Params,
-		Description:       bs.Description,
+		Params:            params,
+		Description:       desc,
 		Encoding:          bs.Encoding,
 		Parts:             parts,
 		Disposition:       bs.Disposition,
-		DispositionParams: bs.DispositionParams,
+		DispositionParams: dispParams,
 	}
 }
 
@@ -38,9 +54,12 @@ func translateEnvelope(e *imap.Envelope) *models.Envelope {
 	if e == nil {
 		return nil
 	}
+	// TODO: where we should send error?
+	subject, _ := charset.DecodeHeader(e.Subject)
+
 	return &models.Envelope{
 		Date:      e.Date,
-		Subject:   e.Subject,
+		Subject:   subject,
 		From:      translateAddresses(e.From),
 		ReplyTo:   translateAddresses(e.ReplyTo),
 		To:        translateAddresses(e.To),
@@ -54,8 +73,9 @@ func translateAddress(a *imap.Address) *models.Address {
 	if a == nil {
 		return nil
 	}
+	personalName, _ := charset.DecodeHeader(a.PersonalName)
 	return &models.Address{
-		Name:    a.PersonalName,
+		Name:    personalName,
 		Mailbox: a.MailboxName,
 		Host:    a.HostName,
 	}
2'>12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91