mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-03 02:26:28 +03:00
Very early NOTIFY support, hopefully fix -password on Windows
This commit is contained in:
65
internal/imapserver/notify.go
Normal file
65
internal/imapserver/notify.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package imapserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/emersion/go-imap"
|
||||
"github.com/emersion/go-imap/server"
|
||||
)
|
||||
|
||||
type IMAPNotifyHandler struct {
|
||||
imap.Command
|
||||
}
|
||||
|
||||
func (h *IMAPNotifyHandler) Handle(conn server.Conn) error {
|
||||
// TODO: Support setting NOTIFY subscriptions or not
|
||||
return nil
|
||||
}
|
||||
|
||||
type IMAPNotify struct {
|
||||
server *server.Server
|
||||
log *log.Logger
|
||||
}
|
||||
|
||||
func (ext *IMAPNotify) Capabilities(c server.Conn) []string {
|
||||
if c.Context().State&imap.AuthenticatedState != 0 {
|
||||
return []string{"NOTIFY"}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ext *IMAPNotify) Command(name string) server.HandlerFactory {
|
||||
if name != "NOTIFY" {
|
||||
return nil
|
||||
}
|
||||
return func() server.Handler {
|
||||
return &IMAPNotifyHandler{}
|
||||
}
|
||||
}
|
||||
|
||||
func (ext *IMAPNotify) NotifyNew(id, count int) error {
|
||||
ext.server.ForEachConn(func(c server.Conn) {
|
||||
var resptype imap.StatusRespType
|
||||
if mailbox := c.Context().Mailbox; mailbox != nil && mailbox.Name() == "INBOX" {
|
||||
resptype = imap.StatusRespType(
|
||||
fmt.Sprintf("EXISTS %d", id),
|
||||
)
|
||||
} else {
|
||||
resptype = imap.StatusRespType(
|
||||
fmt.Sprintf("STATUS INBOX (UIDNEXT %d MESSAGES %d)", id+1, count),
|
||||
)
|
||||
}
|
||||
_ = c.WriteResp(&imap.StatusResp{
|
||||
Type: resptype,
|
||||
})
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewIMAPNotify(s *server.Server, log *log.Logger) *IMAPNotify {
|
||||
return &IMAPNotify{
|
||||
server: s,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user