summary refs log tree commit diff stats
path: root/worker/imap
diff options
context:
space:
mode:
Diffstat (limited to 'worker/imap')
-rw-r--r--worker/imap/imap.go44
1 files changed, 13 insertions, 31 deletions
diff --git a/worker/imap/imap.go b/worker/imap/imap.go
index fdcbc38..7afab02 100644
--- a/worker/imap/imap.go
+++ b/worker/imap/imap.go
@@ -7,6 +7,10 @@ import (
 	"github.com/emersion/go-message/charset"
 )
 
+func init() {
+	imap.CharsetReader = charset.Reader
+}
+
 func toSeqSet(uids []uint32) *imap.SeqSet {
 	var set imap.SeqSet
 	for _, uid := range uids {
@@ -24,29 +28,17 @@ func translateBodyStructure(bs *imap.BodyStructure) *models.BodyStructure {
 		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:            params,
-		Description:       desc,
+		Params:            bs.Params,
+		Description:       bs.Description,
 		Encoding:          bs.Encoding,
 		Parts:             parts,
 		Disposition:       bs.Disposition,
-		DispositionParams: dispParams,
+		DispositionParams: bs.DispositionParams,
 	}
 }
 
@@ -54,12 +46,10 @@ 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:   subject,
+		Subject:   e.Subject,
 		From:      translateAddresses(e.From),
 		ReplyTo:   translateAddresses(e.ReplyTo),
 		To:        translateAddresses(e.To),
@@ -69,22 +59,14 @@ func translateEnvelope(e *imap.Envelope) *models.Envelope {
 	}
 }
 
-func translateAddress(a *imap.Address) *models.Address {
-	if a == nil {
-		return nil
-	}
-	personalName, _ := charset.DecodeHeader(a.PersonalName)
-	return &models.Address{
-		Name:    personalName,
-		Mailbox: a.MailboxName,
-		Host:    a.HostName,
-	}
-}
-
 func translateAddresses(addrs []*imap.Address) []*models.Address {
 	var converted []*models.Address
 	for _, addr := range addrs {
-		converted = append(converted, translateAddress(addr))
+		converted = append(converted, &models.Address{
+			Name:    addr.PersonalName,
+			Mailbox: addr.MailboxName,
+			Host:    addr.HostName,
+		})
 	}
 	return converted
 }
* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package config

import (
	"fmt"
	"testing"

	"github.com/gdamore/tcell"
	"github.com/stretchr/testify/assert"
)

func TestGetBinding(t *testing.T) {
	assert := assert.New(t)

	bindings := NewKeyBindings()
	add := func(binding, cmd string) {
		b, _ := ParseBinding(binding, cmd)
		bindings.Add(b)
	}

	add("abc", ":abc")
	add("cba", ":cba")
	add("foo", ":foo")
	add("bar", ":bar")

	test := func(input []KeyStroke, result int, output string) {
		_output, _ := ParseKeyStrokes(output)
		r, out := bindings.GetBinding(input)
		assert.Equal(result, int(r), fmt.Sprintf(
			"%s: Expected result %d, got %d", output, result, r))
		assert.Equal(_output, out, fmt.Sprintf(
			"%s: Expected output %v, got %v", output, _output, out))
	}

	test([]KeyStroke{
		{tcell.KeyRune, 'a'},
	}, BINDING_INCOMPLETE, "")
	test([]KeyStroke{
		{tcell.KeyRune, 'a'},
		{tcell.KeyRune, 'b'},
		{tcell.KeyRune, 'c'},
	}, BINDING_FOUND, ":abc")
	test([]KeyStroke{
		{tcell.KeyRune, 'c'},
		{tcell.KeyRune, 'b'},
		{tcell.KeyRune, 'a'},
	}, BINDING_FOUND, ":cba")
	test([]KeyStroke{
		{tcell.KeyRune, 'f'},
		{tcell.KeyRune, 'o'},
	}, BINDING_INCOMPLETE, "")
	test([]KeyStroke{
		{tcell.KeyRune, '4'},
		{tcell.KeyRune, '0'},
		{tcell.KeyRune, '4'},
	}, BINDING_NOT_FOUND, "")

	add("<C-a>", "c-a")
	test([]KeyStroke{
		{tcell.KeyCtrlA, 0},
	}, BINDING_FOUND, "c-a")
}