mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-12 14:46:28 +03:00
Very early NOTIFY support, hopefully fix -password on Windows
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package imapserver
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
idle "github.com/emersion/go-imap-idle"
|
||||
"github.com/emersion/go-imap/server"
|
||||
"github.com/emersion/go-sasl"
|
||||
)
|
||||
|
||||
type IMAPServer struct {
|
||||
@@ -10,11 +14,27 @@ type IMAPServer struct {
|
||||
backend *Backend
|
||||
}
|
||||
|
||||
func NewIMAPServer(backend *Backend) (*IMAPServer, error) {
|
||||
func NewIMAPServer(backend *Backend, addr string, insecure bool) (*IMAPServer, *IMAPNotify, error) {
|
||||
s := &IMAPServer{
|
||||
server: server.New(backend),
|
||||
backend: backend,
|
||||
}
|
||||
notify := NewIMAPNotify(s.server, backend.Log)
|
||||
s.server.Addr = addr
|
||||
s.server.AllowInsecureAuth = insecure
|
||||
s.server.Debug = os.Stdout
|
||||
s.server.Enable(idle.NewExtension())
|
||||
return s, nil
|
||||
s.server.Enable(notify)
|
||||
s.server.EnableAuth(sasl.Login, func(conn server.Conn) sasl.Server {
|
||||
return sasl.NewLoginServer(func(username, password string) error {
|
||||
_, err := s.backend.Login(nil, username, password)
|
||||
return err
|
||||
})
|
||||
})
|
||||
go func() {
|
||||
if err := s.server.ListenAndServe(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
return s, notify, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user