Get receiving email a step closer with a modified go-smtp
This commit is contained in:
@@ -31,7 +31,7 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, submission
|
||||
if submission {
|
||||
out.handler = &Sender{}
|
||||
out.server.Addr = ":587"
|
||||
out.allowLogin = true // Only allow login on submission ports
|
||||
out.submission = true // Only allow login on submission ports
|
||||
} else {
|
||||
out.handler = &Receiver{}
|
||||
out.server.Addr = ":25"
|
||||
@@ -46,7 +46,7 @@ type concrete struct {
|
||||
store store.Interface
|
||||
server *smtp.Server
|
||||
handler Handler
|
||||
allowLogin bool
|
||||
submission bool
|
||||
|
||||
// Session IDs
|
||||
sid uint64
|
||||
@@ -64,7 +64,7 @@ func (c *concrete) Run() {
|
||||
|
||||
// backend implementation for go-smtp
|
||||
func (c *concrete) Login(user, pass string) (smtp.User, error) {
|
||||
if !c.allowLogin {
|
||||
if !c.submission {
|
||||
return nil, fmt.Errorf("Login is disabled")
|
||||
}
|
||||
|
||||
@@ -87,6 +87,23 @@ func (c *concrete) Login(user, pass string) (smtp.User, error) {
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (c *concrete) AnonymousLogin() (smtp.User, error) {
|
||||
if c.submission {
|
||||
return nil, smtp.AuthRequiredErr
|
||||
}
|
||||
|
||||
session := &Session{
|
||||
ID: atomic.AddUint64(&c.sid, uint64(1)),
|
||||
Account: nil,
|
||||
Handler: c.handler,
|
||||
}
|
||||
|
||||
log.Printf("Beginning anonymous %s session %d", c.name, session.ID)
|
||||
// FIXME: TODO: Track ongoing sessions for termination or notifications
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (c *concrete) Close() error {
|
||||
c.cancel() // FIXME: this doesn't touch the server
|
||||
|
||||
|
Reference in New Issue
Block a user