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

512d400

Author: bmayer3 (bmayer@sibros.tech)

Date: Mon Jan 23 14:32:56 2023 -0300

Parent: e459d8a

Improved docs

Diff

cmd/dovel/main.go

commit 512d4002ee7ccfc83097011e5aef84b48abf7696
Author: bmayer3 <bmayer@sibros.tech>
Date:   Mon Jan 23 14:32:56 2023 -0300

    Improved docs

diff --git a/cmd/dovel/main.go b/cmd/dovel/main.go
index e1fa6c2..187f645 100644
--- a/cmd/dovel/main.go
+++ b/cmd/dovel/main.go
@@ -137,7 +137,7 @@ func main() {
 			mailCfg := file.FileConfig{
 				Root:      hand.Root,
 				Templates: hand.Templates,
-				Password: os.Getenv("DOVEL_PASS"),
+				Password:  os.Getenv("DOVEL_PASS"),
 			}
 			funcs := map[string]any{"heading": heading}
 			mail, err := file.NewFileHandler(mailCfg, funcs)
@@ -145,8 +145,10 @@ func main() {
 				panic(err)
 			}
 
-			http.HandleFunc(hand.Domain+"/", mail.IndexHandler())
-			http.HandleFunc(hand.Domain+"/out", mail.SendHandler())
+			if hand.Templates != "" {
+				http.HandleFunc(hand.Domain+"/", mail.IndexHandler())
+				http.HandleFunc(hand.Domain+"/out", mail.SendHandler())
+			}
 
 			b.handlers[hand.Domain] = mail.Save
 		}

interfaces/file/file.go

commit 512d4002ee7ccfc83097011e5aef84b48abf7696
Author: bmayer3 <bmayer@sibros.tech>
Date:   Mon Jan 23 14:32:56 2023 -0300

    Improved docs

diff --git a/interfaces/file/file.go b/interfaces/file/file.go
index 731c4ed..9e60438 100644
--- a/interfaces/file/file.go
+++ b/interfaces/file/file.go
@@ -12,8 +12,8 @@ import (
 	"net/smtp"
 	"os"
 	"path"
-	"strings"
 	"strconv"
+	"strings"
 	"time"
 
 	"blmayer.dev/x/dovel/interfaces"
@@ -22,9 +22,14 @@ import (
 
 // FileConfig is used to configure the file handler, now it only contains
 // the root folder that holds all emails.
+// Root is where mail should be saved, Templates is an optional field that
+// is the path to templates, to be used in the web server; Password is the
+// password for the x user, for now this is very simple; Domain is used to
+// filter and separate emails, only emails sent to one of your domains are
+// saved, each according to its configuration.
 type FileConfig struct {
 	Root      string
-	Templates string
+	Templates *string
 	Password  string
 	Domain    string
 }
@@ -33,7 +38,7 @@ type FileHandler struct {
 	templates *template.Template
 	root      string
 	password  string
-	domain string
+	domain    string
 }
 
 func NewFileHandler(c FileConfig, fs map[string]any) (FileHandler, error) {
@@ -92,11 +97,11 @@ func (f FileHandler) SendHandler() http.HandlerFunc {
 		body := bytes.Buffer{}
 		form := multipart.NewWriter(&body)
 		email := interfaces.Email{
-			From: fo.Value["from"][0],
-			To: []string{},
-			Cc: []string{},
+			From:    fo.Value["from"][0],
+			To:      []string{},
+			Cc:      []string{},
 			Subject: fo.Value["subject"][0],
-			Date: time.Now(),
+			Date:    time.Now(),
 		}
 		email.ID = fmt.Sprintf("%s%s", strconv.FormatInt(email.Date.Unix(), 10), email.From)
 
@@ -111,7 +116,7 @@ func (f FileHandler) SendHandler() http.HandlerFunc {
 
 		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))
+				email.Cc = append(email.Cc, fmt.Sprintf("%s", cc))
 			}
 			body.WriteString("Cc: " + strings.Join(email.Cc, ", ") + "\r\n")
 		}
@@ -128,9 +133,9 @@ func (f FileHandler) SendHandler() http.HandlerFunc {
 			},
 		)
 		if err != nil {
-		 	println("creatPart error: " + err.Error())
-		 	http.Error(w, "creatPart error"+err.Error(), http.StatusInternalServerError)
-		 	return
+			println("creatPart error: " + err.Error())
+			http.Error(w, "creatPart error"+err.Error(), http.StatusInternalServerError)
+			return
 		}
 		text.Write([]byte(strings.Join(fo.Value["body"], "")))