mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-12 06:36:28 +03:00
Very early NOTIFY support, hopefully fix -password on Windows
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/emersion/go-smtp"
|
||||
"github.com/neilalexander/yggmail/internal/config"
|
||||
"github.com/neilalexander/yggmail/internal/imapserver"
|
||||
"github.com/neilalexander/yggmail/internal/smtpsender"
|
||||
"github.com/neilalexander/yggmail/internal/storage"
|
||||
"github.com/neilalexander/yggmail/internal/utils"
|
||||
@@ -25,6 +26,7 @@ type Backend struct {
|
||||
Config *config.Config
|
||||
Queues *smtpsender.Queues
|
||||
Storage storage.Storage
|
||||
Notify *imapserver.IMAPNotify
|
||||
}
|
||||
|
||||
func (b *Backend) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error) {
|
||||
|
||||
@@ -65,10 +65,17 @@ func (s *SessionRemote) Data(r io.Reader) error {
|
||||
return fmt.Errorf("m.WriteTo: %w", err)
|
||||
}
|
||||
|
||||
if _, err := s.backend.Storage.MailCreate("INBOX", b.Bytes()); err != nil {
|
||||
if id, err := s.backend.Storage.MailCreate("INBOX", b.Bytes()); err != nil {
|
||||
return fmt.Errorf("s.backend.Storage.StoreMessageFor: %w", err)
|
||||
} else {
|
||||
s.backend.Log.Printf("Stored new mail from %s", s.from)
|
||||
|
||||
if count, err := s.backend.Storage.MailCount("INBOX"); err == nil {
|
||||
if err := s.backend.Notify.NotifyNew(id, count); err != nil {
|
||||
s.backend.Log.Println("Failed to notify:", s.from)
|
||||
}
|
||||
}
|
||||
}
|
||||
s.backend.Log.Printf("Stored new mail from %s", s.from)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,17 +2,20 @@ package smtpserver
|
||||
|
||||
import (
|
||||
"github.com/emersion/go-smtp"
|
||||
"github.com/neilalexander/yggmail/internal/imapserver"
|
||||
)
|
||||
|
||||
type SMTPServer struct {
|
||||
server *smtp.Server
|
||||
backend smtp.Backend
|
||||
notify *imapserver.IMAPNotify
|
||||
}
|
||||
|
||||
func NewSMTPServer(backend smtp.Backend) *SMTPServer {
|
||||
func NewSMTPServer(backend smtp.Backend, notify *imapserver.IMAPNotify) *SMTPServer {
|
||||
s := &SMTPServer{
|
||||
server: smtp.NewServer(backend),
|
||||
backend: backend,
|
||||
notify: notify,
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user