list

server

This is the main dovel repository, it has the Go code to run dovel SMTP server.

curl https://dovel.email/server.tar tar

6494320

Author: blmayer (bleemayer@gmail.com)

Date: Sat Mar 11 18:47:19 2023 -0300

Parent: 02fa69b 336468e

Merge branch 'main' of https://blmayer.dev/x/dovel

Diff

cmd/dovel/main.go

commit 64943208ed9f6d2caa09616daea7c07ab7ac9815
Merge: 02fa69b 336468e
Author: blmayer <bleemayer@gmail.com>
Date:   Sat Mar 11 18:47:19 2023 -0300

    Merge branch 'main' of https://blmayer.dev/x/dovel

diff --cc cmd/dovel/main.go
index 8d13472,32aafda..f97cb89
--- a/cmd/dovel/main.go
+++ b/cmd/dovel/main.go
@@@ -1,9 -1,11 +1,13 @@@
  package main
  
  import (
+ 	"crypto"
+ 	"crypto/x509"
  	"encoding/json"
+ 	"encoding/pem"
 +	"fmt"
 +	"io"
+ 	"io/ioutil"
  	"log"
  	"net/http"
  	"os"
@@@ -12,87 -13,21 +16,82 @@@
  
  	"blmayer.dev/x/dovel/config"
  	"blmayer.dev/x/dovel/interfaces"
+ 	"blmayer.dev/x/dovel/interfaces/backend"
  	"blmayer.dev/x/dovel/interfaces/file"
  	"blmayer.dev/x/dovel/interfaces/gwi"
+ 
++	"github.com/OfimaticSRL/parsemail"
  	"github.com/emersion/go-smtp"
- 	"github.com/vraycc/go-parsemail"
  )
  
- type backend struct {
- 	handlers map[string]config.Handler
- }
- 
- func (b backend) NewSession(_ *smtp.Conn) (smtp.Session, error) {
- 	return Session{handlers: b.handlers}, nil
- }
- 
 +// A Session is returned after EHLO.
 +type Session struct {
 +	User     string
 +	handlers map[string]config.Handler
 +}
 +
 +func (s Session) AuthPlain(username, password string) error {
 +	println("connection sent", username, password)
 +	return nil
 +}
 +
 +func (s Session) Mail(from string, opts *smtp.MailOptions) error {
 +	println("Mail from:", from)
 +	return nil
 +}
 +
 +func (s Session) Rcpt(to string) error {
 +	println("Rcpt to:", to)
 +	return nil
 +}
 +
 +func (s Session) Data(r io.Reader) error {
 +	content, err := io.ReadAll(r)
 +	if err != nil {
 +		println("read content", err.Error())
 +		return err
 +	}
 +
 +	email, err := parsemail.Parse(strings.NewReader(string(content)))
 +	if err != nil {
 +		println("parse email", err.Error())
 +		return err
 +	}
 +
 +	// get user from to field
 +	mail := interfaces.ToEmail(email)
 +	for _, to := range mail.To {
 +		userDomain := strings.Split(to, "@")
 +		handler, ok := s.handlers[userDomain[1]]
 +		if !ok {
 +			println("no handler for domain", userDomain[1])
 +			return fmt.Errorf("no handler for domain %s", userDomain)
 +		}
 +		mail.To = []string{to}
 +		if err := handler(mail); err != nil {
 +			println("handler error", err.Error())
 +			return fmt.Errorf("handler error %s", err.Error())
 +		}
 +	}
 +
 +	return nil
 +}
 +
 +func (s Session) Reset() {}
 +
 +func (s Session) Logout() error {
 +	println("logged out")
 +	return nil
 +}
 +
  var (
  	defaultPort   = "8080"
  	defaultConfig = config.Config{
  		WebPort: &defaultPort,
  		Server: config.ServerConfig{
 +			Domain:  "dovel.email",
 +			Address: ":2525",
+ 			DKIMKeyPath: "dkim.priv",
 -			Domain:      "mail.blmayer.dev",
 -			Address:     ":2525",
  			Inboxes: []config.InboxConfig{
  				{
  					Domain:    "localhost",
@@@ -121,7 -75,10 +139,7 @@@ func main() 
  		switch hand.Handler {
  		case "gwi":
  			g := gwi.GWIConfig{Root: hand.Root}
- 			b.handlers[hand.Domain] = g.GwiEmailHandler
 -			g.Commands = map[string]func(email interfaces.Email, thread string) error{
 -				"close": g.Close,
 -			}
+ 			b.Handlers[hand.Domain] = g.GwiEmailHandler
  		case "file":
  			mailCfg := file.FileConfig{
  				Root:      hand.Root,

config/config.go

commit 64943208ed9f6d2caa09616daea7c07ab7ac9815
Merge: 02fa69b 336468e
Author: blmayer <bleemayer@gmail.com>
Date:   Sat Mar 11 18:47:19 2023 -0300

    Merge branch 'main' of https://blmayer.dev/x/dovel

go.mod

commit 64943208ed9f6d2caa09616daea7c07ab7ac9815
Merge: 02fa69b 336468e
Author: blmayer <bleemayer@gmail.com>
Date:   Sat Mar 11 18:47:19 2023 -0300

    Merge branch 'main' of https://blmayer.dev/x/dovel

diff --cc go.mod
index fb35e14,f159123..e90a2ab
--- a/go.mod
+++ b/go.mod
@@@ -3,9 -3,11 +3,10 @@@ module blmayer.dev/x/dove
  go 1.19
  
  require (
 -	github.com/OfimaticSRL/parsemail v0.0.0-20230123231945-3a41f46bbfa4
++	github.com/OfimaticSRL/parsemail v0.0.0-20230215211201-e1c318cd177f
+ 	github.com/emersion/go-msgauth v0.6.6
 -	github.com/emersion/go-smtp v0.15.0
 -	github.com/go-git/go-git/v5 v5.4.2
 -	github.com/marcospgmelo/parsemail v1.3.1-0.20201020162348-38663e9311e7
 +	github.com/emersion/go-smtp v0.16.0
 +	github.com/go-git/go-git/v5 v5.6.0
- 	github.com/vraycc/go-parsemail v0.0.0-20221110135954-331ae329fca6
  )
  
  require (

go.sum

commit 64943208ed9f6d2caa09616daea7c07ab7ac9815
Merge: 02fa69b 336468e
Author: blmayer <bleemayer@gmail.com>
Date:   Sat Mar 11 18:47:19 2023 -0300

    Merge branch 'main' of https://blmayer.dev/x/dovel

diff --cc go.sum
index fb79f45,a59b1a1..5fd6b22
--- a/go.sum
+++ b/go.sum
@@@ -1,13 -1,16 +1,15 @@@
  github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
  github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
  github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
 -github.com/OfimaticSRL/parsemail v0.0.0-20230123231945-3a41f46bbfa4 h1:C6vTd1O7r8ZHfa/BR45An6pahVkwa9NJYRwf4QFk4Jg=
 -github.com/OfimaticSRL/parsemail v0.0.0-20230123231945-3a41f46bbfa4/go.mod h1:MeyUFKQUXa5bD0bfy+wf3eMotz8NdY/VxXYOQkUuHFg=
 -github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
 -github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 h1:ra2OtmuW0AE5csawV4YXMNGNQQXvLRps3z2Z59OPO+I=
++github.com/OfimaticSRL/parsemail v0.0.0-20230215211201-e1c318cd177f h1:gna0qZzrWwiOizWzu4bwQzsnANcDpc2OvYeDcagGIAc=
++github.com/OfimaticSRL/parsemail v0.0.0-20230215211201-e1c318cd177f/go.mod h1:MeyUFKQUXa5bD0bfy+wf3eMotz8NdY/VxXYOQkUuHFg=
  github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4/go.mod h1:UBYPn8k0D56RtnR8RFQMjmh4KrZzWJ5o7Z9SYjossQ8=
 -github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
 +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
 +github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
  github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
 -github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
 +github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
 +github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
 +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
  github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
  github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
  github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
@@@ -17,26 -20,34 +19,33 @@@ github.com/creack/pty v1.1.9/go.mod h1:
  github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
  github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
  github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+ github.com/emersion/go-message v0.11.2/go.mod h1:C4jnca5HOTo4bGN9YdqNQM9sITuT3Y0K6bSUw9RklvY=
+ github.com/emersion/go-message v0.15.0/go.mod h1:wQUEfE+38+7EW8p8aZ96ptg6bAb1iwdgej19uXASlE4=
+ github.com/emersion/go-milter v0.3.3/go.mod h1:ablHK0pbLB83kMFBznp/Rj8aV+Kc3jw8cxzzmCNLIOY=
+ github.com/emersion/go-msgauth v0.6.6 h1:buv5lL8v/3v4RpHnQFS2IPhE3nxSRX+AxnrEJbDbHhA=
+ github.com/emersion/go-msgauth v0.6.6/go.mod h1:A+/zaz9bzukLM6tRWRgJ3BdrBi+TFKTvQ3fGMFOI9SM=
 -github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21 h1:OJyUGMJTzHTd1XQp98QTaHernxMYzRaOasRir9hUlFQ=
  github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
 -github.com/emersion/go-smtp v0.15.0 h1:3+hMGMGrqP/lqd7qoxZc1hTU8LY8gHV9RFGWlqSDmP8=
 -github.com/emersion/go-smtp v0.15.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
 +github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead h1:fI1Jck0vUrXT8bnphprS1EoVRe2Q5CKCX8iDlpqjQ/Y=
 +github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ=
 +github.com/emersion/go-smtp v0.16.0 h1:eB9CY9527WdEZSs5sWisTmilDX7gG+Q/2IdRcmubpa8=
 +github.com/emersion/go-smtp v0.16.0/go.mod h1:qm27SGYgoIPRot6ubfQ/GpiPy/g3PaZAVRxiO/sDUgQ=
+ github.com/emersion/go-textwrapper v0.0.0-20160606182133-d0e65e56babe/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
+ github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U=
 -github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
  github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
  github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
 -github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
 -github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
 +github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
  github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
  github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
 -github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
 -github.com/go-git/go-billy/v5 v5.3.1 h1:CPiOUAzKtMRvolEKw+bG1PLRpT7D3LIs3/3ey4Aiu34=
  github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
 -github.com/go-git/go-git-fixtures/v4 v4.2.1 h1:n9gGL1Ct/yIw+nfsfr8s4+sbhT+Ncu2SubfXjIWgci8=
 -github.com/go-git/go-git-fixtures/v4 v4.2.1/go.mod h1:K8zd3kDUAykwTdDCr+I0per6Y6vMiRR/nnVTBtavnB0=
 -github.com/go-git/go-git/v5 v5.4.2 h1:BXyZu9t0VkbiHtqrsvdq39UDhGJTl1h55VW6CSC4aY4=
 -github.com/go-git/go-git/v5 v5.4.2/go.mod h1:gQ1kArt6d+n+BGd+/B/I74HwRTLhth2+zti4ihgckDc=
 -github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
 -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
 -github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
 +github.com/go-git/go-billy/v5 v5.4.0/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg=
 +github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4=
 +github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg=
 +github.com/go-git/go-git-fixtures/v4 v4.3.1 h1:y5z6dd3qi8Hl+stezc8p3JxDkoTRqMAlKnXHuzrfjTQ=
 +github.com/go-git/go-git-fixtures/v4 v4.3.1/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo=
 +github.com/go-git/go-git/v5 v5.6.0 h1:JvBdYfcttd+0kdpuWO7KTu0FYgCf5W0t5VwkWGobaa4=
 +github.com/go-git/go-git/v5 v5.6.0/go.mod h1:6nmJ0tJ3N4noMV1Omv7rC5FG3/o8Cm51TB4CJp7mRmE=
 +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
 +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
  github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
  github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
  github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
@@@ -51,93 -64,72 +60,95 @@@ github.com/kr/pty v1.1.1/go.mod h1:pFQY
  github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
  github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
  github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
 -github.com/marcospgmelo/parsemail v1.3.1-0.20201020162348-38663e9311e7 h1:KlXrFiVXXvxkEmHWmHErAxzBL7ynvJvzdLr8ZZRgYbc=
 -github.com/marcospgmelo/parsemail v1.3.1-0.20201020162348-38663e9311e7/go.mod h1:bzTPHUEfHfbAxgj0nNHBAEH50bbKSkSuNVx8HEpO+5A=
+ github.com/martinlindhe/base36 v1.0.0/go.mod h1:+AtEs8xrBpCeYgSLoY/aJ6Wf37jtBuR0s35750M27+8=
  github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
  github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
 -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
 -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
 +github.com/mmcloughlin/avo v0.5.0/go.mod h1:ChHFdoV7ql95Wi7vuq2YT1bwCJqiWdZrQ1im3VujLYM=
  github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
 -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 +github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4=
 +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI=
  github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
  github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
  github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
  github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
  github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
 -github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
 -github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
 -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
 +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
 +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
  github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
 +github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0=
 +github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag=
  github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
  github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
  github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
  github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
  github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
- github.com/vraycc/go-parsemail v0.0.0-20221110135954-331ae329fca6 h1:heYIND9fCman7upF5lbS2YJja7h6a6jScqtTorle5ds=
- github.com/vraycc/go-parsemail v0.0.0-20221110135954-331ae329fca6/go.mod h1:t/GKLZo41c5vN5lo5suZXFRlFXvEqjLgIOYlVNq1Q1A=
 -github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0=
  github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
  github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
 -golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
 -golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
 -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
 +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
 +golang.org/x/arch v0.1.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
 +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
  golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+ golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 +golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
  golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 -golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
 +golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
 +golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
  golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
 +golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
 +golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
 +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 +golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
  golang.org/x/mod v0.7.0 h1:LapD9S96VoQRhi/GrNTqeBJFrUjs5UHCAtTlgwA5oZA=
 +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
  golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
 -golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
  golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
 -golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
 +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
 +golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
 +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
  golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
 -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
 -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 -golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 +golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
 +golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
 +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
  golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 -golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 -golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
  golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
  golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
 +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 +golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
  golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 +golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
 +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
  golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 +golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 +golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
 +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
 +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
  golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
  golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
 -golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
 +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
 +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
 +golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
  golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
 +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
 +golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA=
  golang.org/x/tools v0.3.0 h1:SrNbZl6ECOS1qFzgTdQfWXZM9XBkiA6tkFrH9YSTPHM=
  golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
 +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
  gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
  gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
  gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

interfaces/backend/backend.go

commit 64943208ed9f6d2caa09616daea7c07ab7ac9815
Merge: 02fa69b 336468e
Author: blmayer <bleemayer@gmail.com>
Date:   Sat Mar 11 18:47:19 2023 -0300

    Merge branch 'main' of https://blmayer.dev/x/dovel

diff --cc interfaces/backend/backend.go
index 0000000,48f9b4a..6dd9d7c
mode 000000,100644..100644
--- a/interfaces/backend/backend.go
+++ b/interfaces/backend/backend.go
@@@ -1,0 -1,223 +1,216 @@@
+ // package backend contains interfaces that are passed to the common
+ // functions on the server and web projects. You can import this to use
+ // on templates and handlers.
+ package backend
+ 
+ import (
+ 	"bytes"
+ 	"crypto"
+ 	"fmt"
+ 	"io"
+ 	"mime/multipart"
+ 	"net"
+ 	"net/http"
+ 	"strconv"
+ 	"strings"
+ 	"time"
+ 
+ 	"blmayer.dev/x/dovel/config"
+ 	"blmayer.dev/x/dovel/interfaces"
+ 	"github.com/OfimaticSRL/parsemail"
+ 	"github.com/emersion/go-msgauth/dkim"
+ 	"github.com/emersion/go-smtp"
+ )
+ 
+ // A Session is returned after EHLO.
+ type Session struct {
+ 	User     string
+ 	handlers map[string]config.Handler
+ }
+ 
+ func (s Session) AuthPlain(username, password string) error {
+ 	println("connection sent", username, password)
+ 	return nil
+ }
+ 
 -func (s Session) Mail(from string, opts smtp.MailOptions) error {
++func (s Session) Mail(from string, opts *smtp.MailOptions) error {
+ 	println("Mail from:", from)
+ 	return nil
+ }
+ 
+ func (s Session) Rcpt(to string) error {
+ 	println("Rcpt to:", to)
+ 	return nil
+ }
+ 
+ func (s Session) Data(r io.Reader) error {
+ 	content, err := io.ReadAll(r)
+ 	if err != nil {
+ 		println("read content", err.Error())
+ 		return err
+ 	}
+ 
+ 	email, err := parsemail.Parse(strings.NewReader(string(content)))
+ 	if err != nil {
+ 		println("parse email", err.Error())
+ 		return err
+ 	}
+ 
+ 	// get user from to field
+ 	mail := interfaces.ToEmail(email)
+ 	for _, to := range mail.To {
+ 		userDomain := strings.Split(to, "@")
+ 		handler, ok := s.handlers[userDomain[1]]
+ 		if !ok {
+ 			println("no handler for domain", userDomain[1])
+ 			return fmt.Errorf("no handler for domain %s", userDomain)
+ 		}
+ 		mail.To = []string{to}
 -		if err := handler(mail, content); err != nil {
++		if err := handler(mail); err != nil {
+ 			println("handler error", err.Error())
+ 			return fmt.Errorf("handler error %s", err.Error())
+ 		}
+ 	}
+ 
+ 	return nil
+ }
+ 
+ func (s Session) Reset() {}
+ 
+ func (s Session) Logout() error {
+ 	println("logged out")
+ 	return nil
+ }
+ 
+ type Backend struct {
+ 	Handlers   map[string]config.Handler
+ 	PrivateKey crypto.Signer
+ }
+ 
+ func (b Backend) NewSession(_ *smtp.Conn) (smtp.Session, error) {
+ 	return Session{handlers: b.Handlers}, nil
+ }
+ 
 -func (b Backend) Login(state *smtp.ConnectionState, username, password string) (smtp.Session, error) {
 -	return Session{}, nil
 -}
 -
 -func (b Backend) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, error) {
 -	return Session{handlers: b.Handlers}, nil
 -}
 -
 -func (b Backend) SendHandler(saveFunction func(e interfaces.Email, b []byte) error) http.HandlerFunc {
++func (b Backend) SendHandler(saveFunction config.Handler) http.HandlerFunc {
+ 	return func(w http.ResponseWriter, r *http.Request) {
+ 		println("backend sending email")
+ 		if err := r.ParseMultipartForm(20 * 1024 * 1024); err != nil {
+ 			println("form error: " + err.Error())
+ 			http.Error(w, "form error"+err.Error(), http.StatusNotAcceptable)
+ 			return
+ 		}
+ 		fo := r.MultipartForm
+ 
+ 		body := bytes.Buffer{}
+ 		form := multipart.NewWriter(&body)
+ 		email := interfaces.Email{
+ 			From:    fo.Value["from"][0],
+ 			To:      []string{},
+ 			Cc:      []string{},
+ 			Subject: fo.Value["subject"][0],
+ 			Date:    time.Now(),
+ 		}
+ 		email.ID = fmt.Sprintf("%s%s", strconv.FormatInt(email.Date.Unix(), 10), email.From)
+ 
+ 		// headers
+ 		body.WriteString("MIME-Version: 1.0\r\n")
+ 		body.WriteString("From: " + email.From + "\r\n")
+ 
+ 		for _, to := range fo.Value["to"] {
+ 			email.To = append(email.To, fmt.Sprintf("%s", to))
+ 		}
+ 		body.WriteString("To: " + strings.Join(email.To, ", ") + "\r\n")
+ 
+ 		if len(fo.Value["cc"]) > 0 && fo.Value["cc"][0] != "" {
+ 			for _, cc := range fo.Value["cc"] {
+ 				email.Cc = append(email.Cc, fmt.Sprintf("%s", cc))
+ 			}
+ 			body.WriteString("Cc: " + strings.Join(email.Cc, ", ") + "\r\n")
+ 		}
+ 
+ 		body.WriteString(fmt.Sprintf("Message-ID: <%s>\r\n", email.ID))
+ 
+ 		body.WriteString("Date: " + email.Date.Format(time.RFC1123Z) + "\r\n")
+ 		body.WriteString("Subject: " + email.Subject + "\r\n")
+ 		body.WriteString("Content-Type: multipart/mixed; boundary=" + form.Boundary() + "\r\n\r\n")
+ 
+ 		text, err := form.CreatePart(
+ 			map[string][]string{
+ 				"Content-Type": {"text/plain; charset=\"UTF-8\""},
+ 			},
+ 		)
+ 		if err != nil {
+ 			println("creatPart error: " + err.Error())
+ 			http.Error(w, "creatPart error"+err.Error(), http.StatusInternalServerError)
+ 			return
+ 		}
+ 		text.Write([]byte(strings.Join(fo.Value["body"], "")))
+ 
+ 		for name, fi := range fo.File {
+ 			part, err := form.CreateFormFile(name, name)
+ 			if err != nil {
+ 				println("error creating form file: " + err.Error())
+ 				continue
+ 			}
+ 			attach, err := fi[0].Open()
+ 			if err != nil {
+ 				println("error getting attachment: " + err.Error())
+ 				continue
+ 			}
+ 			defer attach.Close()
+ 
+ 			content, err := io.ReadAll(attach)
+ 			if err != nil {
+ 				println("error getting attachment: " + err.Error())
+ 				continue
+ 			}
+ 			part.Write(content)
+ 		}
+ 		form.Close()
+ 
+ 		// dkim
+ 		payload := bytes.Buffer{}
+ 		options := &dkim.SignOptions{
+ 			Domain:   "mail.blmayer.dev",
+ 			Selector: "dkim",
+ 			Signer:   b.PrivateKey,
+ 		}
+ 		if err := dkim.Sign(&payload, &body, options); err != nil {
+ 			println("failed to sign body:", err.Error())
+ 		}
++		email.Body = payload.String()
+ 
+ 		// dns mx for email
+ 		for _, to := range email.To {
+ 			addr := strings.Split(to, "@")
+ 			mxs, err := net.LookupMX(addr[1])
+ 			if err != nil {
+ 				println("get MX error: " + err.Error())
+ 				http.Error(w, "get MX error"+err.Error(), http.StatusInternalServerError)
+ 				return
+ 			}
+ 			if len(mxs) == 0 {
+ 				println("empty MX response")
+ 				http.Error(w, "empty MX response", http.StatusInternalServerError)
+ 				return
+ 			}
+ 
+ 			server := mxs[0].Host + ":smtp"
+ 			err = smtp.SendMail(
+ 				server,
+ 				nil,
+ 				email.From,
+ 				[]string{to},
 -				&payload,
++				bytes.NewReader([]byte(email.Body)),
+ 			)
+ 			if err != nil {
+ 				println("sendMail error: " + err.Error())
+ 				http.Error(w, "error sending email: "+err.Error(), http.StatusInternalServerError)
+ 				return
+ 			}
+ 
 -			saveFunction(email, payload.Bytes())
++			saveFunction(email)
+ 		}
+ 		http.Redirect(w, r, "/", http.StatusFound)
+ 	}
+ }

interfaces/file/file.go

commit 64943208ed9f6d2caa09616daea7c07ab7ac9815
Merge: 02fa69b 336468e
Author: blmayer <bleemayer@gmail.com>
Date:   Sat Mar 11 18:47:19 2023 -0300

    Merge branch 'main' of https://blmayer.dev/x/dovel

diff --cc interfaces/file/file.go
index a444763,74b4b72..a7c6ea9
--- a/interfaces/file/file.go
+++ b/interfaces/file/file.go
@@@ -206,7 -100,9 +100,9 @@@ func (f FileHandler) Save(email interfa
  		println("file create", err.Error())
  		return err
  	}
+ 	defer file.Close()
+ 
 -	_, err = file.Write(content)
 +	_, err = file.Write([]byte(email.Body))
  	if err != nil {
  		println("file write", err.Error())
  		return err
@@@ -224,7 -120,9 +120,9 @@@ func (f FileHandler) SaveSent(email int
  		println("file create", err.Error())
  		return err
  	}
+ 	defer file.Close()
+ 
 -	_, err = file.Write(content)
 +	_, err = file.Write([]byte(email.Body))
  	if err != nil {
  		println("file write", err.Error())
  		return err

www/style-min.html

commit 64943208ed9f6d2caa09616daea7c07ab7ac9815
Merge: 02fa69b 336468e
Author: blmayer <bleemayer@gmail.com>
Date:   Sat Mar 11 18:47:19 2023 -0300

    Merge branch 'main' of https://blmayer.dev/x/dovel

diff --cc www/style-min.html
index 9cf4f48,ac5fb98..4eb6abd
--- a/www/style-min.html
+++ b/www/style-min.html
@@@ -1,2 -1,31 +1,28 @@@
- <style>body{width:541;margin:99 auto;background:#000;color:#0f0}a{color:#f0f}</style>
+ <style>
+ 	body {
+ 		width: 541;
+ 		margin: 99 auto;
 -		background: #000;
 -		color: #0f0;
+ 		font-family: monospace;
+ 	}
+ 	a {
 -		color:#f0f
++		color: #888
+ 	}
+ 	input, textarea {
+ 		flex-grow: 1;
 -		background: #000;
+ 		border: none;
 -		border-bottom: 1px solid #0f0;
 -		color: #0f0;
++		border-bottom: 1px solid #888;
++		color: #888;
+ 		font-family: monospace;
+ 	}
+ 	input[type="submit"] {
+ 		text-decoration: underline;
+ 		cursor: pointer;
 -		color: #f0f;
++		color: #888;
+ 	}
+ 	label {
+ 		display: inline-block;
+ 		min-width: 80;
+ 	}
+ 
+ </style>