This repository was archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.go
67 lines (54 loc) · 1.54 KB
/
server.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package move
import (
"errors"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap/server"
)
// A mailbox supporting the MOVE extension.
type Mailbox interface {
// Move the specified message(s) to the end of the specified destination
// mailbox. This means that a new message is created in the target mailbox
// with a new UID, the original message is removed from the source mailbox,
// and it appears to the client as a single action.
//
// If the destination mailbox does not exist, a server SHOULD return an error.
// It SHOULD NOT automatically create the mailbox.
MoveMessages(uid bool, seqset *imap.SeqSet, dest string) error
}
type handler struct {
Command
}
func (h *handler) handle(uid bool, conn server.Conn) error {
mailbox := conn.Context().Mailbox
if mailbox == nil {
return server.ErrNoMailboxSelected
}
if m, ok := mailbox.(Mailbox); ok {
return m.MoveMessages(uid, h.SeqSet, h.Mailbox)
}
return errors.New("MOVE extension not supported")
}
func (h *handler) Handle(conn server.Conn) error {
return h.handle(false, conn)
}
func (h *handler) UidHandle(conn server.Conn) error {
return h.handle(true, conn)
}
type extension struct{}
func (ext *extension) Capabilities(c server.Conn) []string {
if c.Context().State&imap.AuthenticatedState != 0 {
return []string{Capability}
}
return nil
}
func (ext *extension) Command(name string) server.HandlerFactory {
if name != commandName {
return nil
}
return func() server.Handler {
return &handler{}
}
}
func NewExtension() server.Extension {
return &extension{}
}