-
Notifications
You must be signed in to change notification settings - Fork 317
/
Copy pathexpunge.go
50 lines (43 loc) · 1.13 KB
/
expunge.go
1
2
3
4
5
6
7
8
9
10
11
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
package imapserver
import (
"github.com/emersion/go-imap/v2"
"github.com/emersion/go-imap/v2/internal/imapwire"
)
func (c *Conn) handleExpunge(dec *imapwire.Decoder) error {
if !dec.ExpectCRLF() {
return dec.Err()
}
return c.expunge(nil)
}
func (c *Conn) handleUIDExpunge(dec *imapwire.Decoder) error {
var uidSet imap.UIDSet
if !dec.ExpectSP() || !dec.ExpectUIDSet(&uidSet) || !dec.ExpectCRLF() {
return dec.Err()
}
return c.expunge(&uidSet)
}
func (c *Conn) expunge(uids *imap.UIDSet) error {
if err := c.checkState(imap.ConnStateSelected); err != nil {
return err
}
w := &ExpungeWriter{conn: c}
return c.session.Expunge(w, uids)
}
func (c *Conn) writeExpunge(seqNum uint32) error {
enc := newResponseEncoder(c)
defer enc.end()
enc.Atom("*").SP().Number(seqNum).SP().Atom("EXPUNGE")
return enc.CRLF()
}
// ExpungeWriter writes EXPUNGE updates.
type ExpungeWriter struct {
conn *Conn
}
// WriteExpunge notifies the client that the message with the provided sequence
// number has been deleted.
func (w *ExpungeWriter) WriteExpunge(seqNum uint32) error {
if w.conn == nil {
return nil
}
return w.conn.writeExpunge(seqNum)
}