mox/imapserver/idle_test.go
Mechiel Lukkien cc4ecf2927
imap continuations must have a space after the "+"
prevented at least the gmail/mail (?) android app from appending a sent message
to the sent mailbox.
2023-07-24 19:54:55 +02:00

52 lines
1.1 KiB
Go

package imapserver
import (
"fmt"
"testing"
"time"
"github.com/mjl-/mox/imapclient"
)
func TestIdle(t *testing.T) {
tc1 := start(t)
defer tc1.close()
tc1.transactf("ok", "login mjl@mox.example testtest")
tc2 := startNoSwitchboard(t)
defer tc2.close()
tc2.transactf("ok", "login mjl@mox.example testtest")
tc1.transactf("ok", "select inbox")
tc2.transactf("ok", "select inbox")
// todo: test with delivery through smtp
tc2.cmdf("", "idle")
tc2.readprefixline("+ ")
done := make(chan error)
go func() {
defer func() {
x := recover()
if x != nil {
done <- fmt.Errorf("%v", x)
}
}()
untagged, _ := tc2.client.ReadUntagged()
var exists imapclient.UntaggedExists
tuntagged(tc2.t, untagged, &exists)
// todo: validate the data we got back.
tc2.writelinef("done")
done <- nil
}()
tc1.transactf("ok", "append inbox () {%d+}\r\n%s", len(exampleMsg), exampleMsg)
timer := time.NewTimer(time.Second)
defer timer.Stop()
select {
case err := <-done:
tc1.check(err, "idle")
case <-timer.C:
t.Fatalf("idle did not finish")
}
}