mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-20 02:06:28 +03:00
Initial commit
This commit is contained in:
33
internal/imapserver/backend.go
Normal file
33
internal/imapserver/backend.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package imapserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/emersion/go-imap"
|
||||
"github.com/emersion/go-imap/backend"
|
||||
"github.com/neilalexander/yggmail/internal/config"
|
||||
"github.com/neilalexander/yggmail/internal/storage"
|
||||
)
|
||||
|
||||
type Backend struct {
|
||||
Config *config.Config
|
||||
Log *log.Logger
|
||||
Storage storage.Storage
|
||||
}
|
||||
|
||||
func (b *Backend) Login(_ *imap.ConnInfo, username, password string) (backend.User, error) {
|
||||
if authed, err := b.Storage.TryAuthenticate(username, password); err != nil {
|
||||
b.Log.Printf("Failed to authenticate IMAP user %q due to error: %s", username, err)
|
||||
return nil, fmt.Errorf("failed to authenticate: %w", err)
|
||||
} else if !authed {
|
||||
b.Log.Printf("Failed to authenticate IMAP user %q\n", username)
|
||||
return nil, backend.ErrInvalidCredentials
|
||||
}
|
||||
defer b.Log.Printf("Authenticated IMAP user %q\n", username)
|
||||
user := &User{
|
||||
backend: b,
|
||||
username: username,
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
Reference in New Issue
Block a user