Get as far as storing an incoming mail in crockery.db

This commit is contained in:
2018-03-08 01:39:24 +00:00
parent be7ca459a5
commit b4537d1283
6 changed files with 123 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"net/mail"
"sync/atomic"
"github.com/emersion/go-smtp"
@@ -74,6 +75,30 @@ func (m *mta) AnonymousLogin() (smtp.User, error) {
// User implementation for go-smtp after this point
// Since only anonymous login is permitted, there's no need to introduce an
// intermediary to track the logged-in user.
//
// TODO: wildcard address support. For now, just dump everything directly
// into a single hardcoded mailbox per-account
func (m *mta) ServeSMTP(from string, to []string, r io.Reader) error {
return fmt.Errorf("Not yet implemented")
emails := make([]string, len(to))
for i, entry := range to {
addr, err := mail.ParseAddress(entry) // FIXME: should this be AddressList?
if err != nil {
return err
}
emails[i] = addr.Address
}
log.Printf("emails: %#v", emails)
recipients, err := m.store.FindAccounts(emails...)
if err != nil {
return err
}
if len(recipients) != len(to) {
return fmt.Errorf("At least one recipient is not known locally")
}
return m.store.SpoolMessage(recipients, r)
}