This is the main dovel repository, it has the Go code to run dovel SMTP server.
Author: b (git@mail.blmayer.dev)
Date: Tue Jul 18 00:04:50 2023 -0300
Parent: cf90e66
Fixed more bugs
commit 1dc8f91bddb1ff1b313c0d3388ed8cb4453b3060
Author: b <git@mail.blmayer.dev>
Date: Tue Jul 18 00:04:50 2023 -0300
Fixed more bugs
diff --git a/cmd/dovel/backend.go b/cmd/dovel/backend.go
index 5b61426..f06c52f 100644
--- a/cmd/dovel/backend.go
+++ b/cmd/dovel/backend.go
@@ -7,6 +7,8 @@ import (
"net/mail"
"strings"
+ "blmayer.dev/x/vault"
+
"git.derelict.garden/dovel/email/interfaces"
"github.com/OfimaticSRL/parsemail"
"github.com/emersion/go-smtp"
@@ -17,12 +19,15 @@ type Session struct {
user string
handlers map[string]interfaces.Mailer
from string
- to string
+ tos []string
+ vault vault.Vault[interfaces.WebUser]
}
func (s Session) AuthPlain(username, password string) error {
println("connection sent", username, password)
- // call vault
+ if s.vault.Validate(username, password) {
+ s.user = username
+ }
return nil
}
@@ -34,46 +39,46 @@ func (s Session) Mail(from string, opts *smtp.MailOptions) error {
func (s Session) Rcpt(to string) error {
println("Rcpt to:", to)
- s.to = to
+ s.tos = append(s.tos, to)
return nil
}
func (s Session) Data(r io.Reader) error {
- email, err := mail.ReadMessage(r)
- if err != nil {
- println("parse email", err.Error())
- return err
- }
-
from, err := mail.ParseAddress(s.from)
if err != nil {
println("parse address", err.Error())
return err
}
- fromDomain := strings.Split(from, "@")[1]
- tos, err := mail.ParseAddressList(s.to)
+ fromDomain := strings.Split(from.Address, "@")[1]
+ tos, err := mail.ParseAddressList(strings.Join(s.tos, ", "))
if err != nil {
println("parse addresslist", err.Error())
return err
}
+ email, err := parsemail.Parse(r)
+ if err != nil {
+ println("parse email", err)
+ return err
+ }
+ m := interfaces.ToEmail(email)
for _, to := range tos {
localdom := strings.Split(to.Address, "@")
if h, ok := s.handlers[localdom[1]]; ok {
- err = h.Save(r)
+ err = h.Save(m)
} else {
- if user == "" {
+ if s.user == "" {
return fmt.Errorf("needs auth")
}
h, ok = s.handlers[fromDomain]
if !ok {
return fmt.Errorf("from is wrong")
}
- err = h.Send(r)
+ err = h.Send(m, interfaces.Opt{})
}
if err != nil {
println("handler error", err.Error())
- return
+ return err
}
}
@@ -93,6 +98,6 @@ type backend struct {
}
func (b backend) NewSession(_ *smtp.Conn) (smtp.Session, error) {
- return Session{handlers: b.Handlers}, nil
+ return Session{handlers: b.Handlers, tos:[]string{}}, nil
}
commit 1dc8f91bddb1ff1b313c0d3388ed8cb4453b3060
Author: b <git@mail.blmayer.dev>
Date: Tue Jul 18 00:04:50 2023 -0300
Fixed more bugs
diff --git a/cmd/dovel/main.go b/cmd/dovel/main.go
index 560d97f..9f2b4d9 100644
--- a/cmd/dovel/main.go
+++ b/cmd/dovel/main.go
@@ -42,8 +42,12 @@ var (
)
func main() {
- configPath := path.Join(os.UserConfigDir(), "dovel", "config.json")
- configFile, err := os.Open(configPath)
+ configPath, err := os.UserConfigDir()
+ if err != nil {
+ println(err, "using ~/.config/dovel/config.json")
+ configPath = "~/.config"
+ }
+ configFile, err := os.Open(path.Join(configPath, "dovel", "config.json"))
if err != nil {
println("open config", err.Error(), ". Using defaults")
cfg = defaultConfig