Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/cmd/mokapi/main.go",
"program": "${workspaceRoot}/cmd/mokapi",
"env": {"MOKAPI_Log.Level": "debug", "MOKAPI_Providers.File.Directory": "data", "DEVUSER": "lehmannmar"}, //"MOKAPI_configFile": "config.yml",
"args": ["--Log.Format=json", "--Api.Port=8081"],//"--Log.Level=debug", , "--configFile", "config.yml"
"cwd": "${workspaceRoot}"
Expand Down
4 changes: 2 additions & 2 deletions imap/idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package imap
import (
"io"
"net/textproto"
"strings"
)

type UpdateWriter interface {
Expand Down Expand Up @@ -39,8 +40,7 @@ func (c *conn) handleIdle(tag string) error {
return err
}

_, cmd, _ := parseLine(line)
if cmd != "DONE" {
if strings.ToUpper(line) != "DONE" {
return c.writeResponse(tag, &response{
status: bad,
text: "Expected DONE to end IDLE",
Expand Down
47 changes: 44 additions & 3 deletions imap/idle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package imap_test

import (
"fmt"
"github.com/stretchr/testify/require"
"mokapi/imap"
"mokapi/imap/imaptest"
"mokapi/try"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestIdle(t *testing.T) {
Expand Down Expand Up @@ -62,7 +63,47 @@ func TestIdle(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "+ idling", res)

res, err = c.SendRaw("A01 DONE")
res, err = c.SendRaw("DONE")
require.NoError(t, err)
require.Equal(t, "A01 OK IDLE terminated", res)
},
},
{
name: "idle and done with lower case",
handler: func(t *testing.T) imap.Handler {
return &imaptest.Handler{
SelectFunc: func(mailbox string, readonly bool, session map[string]interface{}) (*imap.Selected, error) {
return &imap.Selected{}, nil
},
IdleFunc: func(w imap.UpdateWriter, done chan struct{}, session map[string]interface{}) error {
session["idle"] = done
return nil
},
UnselectFunc: func(session map[string]interface{}) error {
done := session["idle"].(chan struct{})
doneClosed := false
select {
case <-done:
doneClosed = true
case <-time.After(time.Second):
}

require.True(t, doneClosed, "done is closed")
return nil
},
}
},
test: func(t *testing.T, c *imap.Client) {
err := c.PlainAuth("", "bob", "password")
require.NoError(t, err)
_, err = c.Select("INBOX", false)
require.NoError(t, err)

res, err := c.SendRaw("A01 idle")
require.NoError(t, err)
require.Equal(t, "+ idling", res)

res, err = c.SendRaw("done")
require.NoError(t, err)
require.Equal(t, "A01 OK IDLE terminated", res)
},
Expand Down Expand Up @@ -125,7 +166,7 @@ func TestIdle(t *testing.T) {
}()

c := imap.NewClient(fmt.Sprintf("localhost:%v", p))
defer c.Close()
defer func() { _ = c.Close() }()

_, err := c.Dial()
require.NoError(t, err)
Expand Down