Skip to content

Commit e23e10a

Browse files
committed
Add missing IDLE command and response
1 parent c465e67 commit e23e10a

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

commands/idle.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package commands
2+
3+
import (
4+
"github.com/emersion/go-imap"
5+
)
6+
7+
// An IDLE command.
8+
// Se RFC 2177 section 3.
9+
type Idle struct{}
10+
11+
func (cmd *Idle) Command() *imap.Command {
12+
return &imap.Command{Name: "IDLE"}
13+
}
14+
15+
func (cmd *Idle) Parse(fields []interface{}) error {
16+
return nil
17+
}

responses/idle.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package responses
2+
3+
import (
4+
"github.com/emersion/go-imap"
5+
)
6+
7+
// An IDLE response.
8+
type Idle struct {
9+
RepliesCh chan []byte
10+
Stop <-chan struct{}
11+
12+
gotContinuationReq bool
13+
}
14+
15+
func (r *Idle) Replies() <-chan []byte {
16+
return r.RepliesCh
17+
}
18+
19+
func (r *Idle) stop() {
20+
r.RepliesCh <- []byte("DONE\r\n")
21+
}
22+
23+
func (r *Idle) Handle(resp imap.Resp) error {
24+
// Wait for a continuation request
25+
if _, ok := resp.(*imap.ContinuationReq); ok && !r.gotContinuationReq {
26+
r.gotContinuationReq = true
27+
28+
// We got a continuation request, wait for r.Stop to be closed
29+
go func() {
30+
<-r.Stop
31+
r.stop()
32+
}()
33+
34+
return nil
35+
}
36+
37+
return ErrUnhandled
38+
}

0 commit comments

Comments
 (0)