This is the main dovel repository, it has the Go code to run dovel SMTP server.
Author: bmayer3 (bmayer@sibros.tech)
Date: Mon Apr 24 14:05:40 2023 -0300
Parent: 163adfe
Moved email reading to interfaces * Improved pages
commit a98c9e1314fda90fb3460456f1646ce656c464ba Author: bmayer3 <bmayer@sibros.tech> Date: Mon Apr 24 14:05:40 2023 -0300 Moved email reading to interfaces * Improved pages diff --git a/Makefile b/Makefile index 160ccdc..b9f0f8c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: clean deploy deploy-site deploy-assets deploy-pages -dovel: $(wildcard cmd/dovel/*.go interfaces/*/*.go config/*.go) +dovel: $(wildcard cmd/dovel/*.go interfaces/*/*.go config/*.go interfaces/*.go) GOARCH=arm GOARM=6 go build -o $@ cmd/dovel/*.go deploy: dovel
commit a98c9e1314fda90fb3460456f1646ce656c464ba Author: bmayer3 <bmayer@sibros.tech> Date: Mon Apr 24 14:05:40 2023 -0300 Moved email reading to interfaces * Improved pages diff --git a/interfaces/file/file.go b/interfaces/file/file.go index 728b8f4..858b628 100644 --- a/interfaces/file/file.go +++ b/interfaces/file/file.go @@ -7,10 +7,8 @@ import ( "bytes" "crypto" "crypto/x509" - "encoding/base64" "encoding/pem" "fmt" - "io" "io/ioutil" "mime/multipart" "net" @@ -275,37 +273,5 @@ func (f FileHandler) Mail(file string) (interfaces.Email, error) { return interfaces.Email{}, err } - email := interfaces.Email{ - ID: mail.MessageID, - From: mail.From[0].Address, - Date: mail.Date, - Subject: mail.Subject, - Body: mail.TextBody, - Attachments: map[string]interfaces.Attachment{}, - } - for _, to := range mail.To { - email.To = append(email.To, to.Address) - } - - if len(mail.Cc) > 0 { - for _, cc := range mail.Cc { - email.Cc = append(email.Cc, cc.Address) - } - } - - for _, a := range mail.Attachments { - content, err := io.ReadAll(a.Data) - if err != nil { - fmt.Println("read attachment", err.Error()) - continue - } - - encContent := base64.StdEncoding.EncodeToString(content) - email.Attachments[a.Filename] = interfaces.Attachment{ - Name: a.Filename, - ContentType: a.ContentType, - Data: []byte(encContent), - } - } - return email, nil + return interfaces.ToEmail(mail), nil }
commit a98c9e1314fda90fb3460456f1646ce656c464ba Author: bmayer3 <bmayer@sibros.tech> Date: Mon Apr 24 14:05:40 2023 -0300 Moved email reading to interfaces * Improved pages diff --git a/interfaces/main.go b/interfaces/main.go index 03e74a4..56d828e 100644 --- a/interfaces/main.go +++ b/interfaces/main.go @@ -4,6 +4,9 @@ package interfaces import ( + "encoding/base64" + "fmt" + "io" "time" "github.com/go-git/go-git/v5/plumbing" @@ -49,6 +52,7 @@ type Attachment struct { } type Email struct { + Headers map[string][]string ID string From string To []string @@ -63,13 +67,15 @@ type Email struct { func ToEmail(mail parsemail.Email) Email { m := Email{ - From: mail.From[0].Address, - To: []string{}, - Cc: []string{}, - Subject: mail.Subject, - ID: mail.MessageID, - Date: mail.Date, - Body: mail.TextBody, + Headers: mail.Header, + From: mail.From[0].Address, + To: []string{}, + Cc: []string{}, + Subject: mail.Subject, + ID: mail.MessageID, + Date: mail.Date, + Body: mail.TextBody, + Attachments: map[string]Attachment{}, } for _, to := range mail.To { m.To = append(m.To, to.Address) @@ -77,6 +83,20 @@ func ToEmail(mail parsemail.Email) Email { for _, cc := range mail.Cc { m.Cc = append(m.Cc, cc.Address) } + for _, a := range mail.Attachments { + content, err := io.ReadAll(a.Data) + if err != nil { + fmt.Println("read attachment", err.Error()) + continue + } + + encContent := base64.StdEncoding.EncodeToString(content) + m.Attachments[a.Filename] = Attachment{ + Name: a.Filename, + ContentType: a.ContentType, + Data: []byte(encContent), + } + } return m } @@ -87,4 +107,3 @@ type Mailer interface { Mails(folder string) ([]Email, error) Mail(file string) (Email, error) } -
commit a98c9e1314fda90fb3460456f1646ce656c464ba Author: bmayer3 <bmayer@sibros.tech> Date: Mon Apr 24 14:05:40 2023 -0300 Moved email reading to interfaces * Improved pages diff --git a/www/compose.html b/www/compose.html index 24d96b0..c9ad0c5 100644 --- a/www/compose.html +++ b/www/compose.html @@ -1,4 +1,9 @@ +<!DOCTYPE html> +<html> + <head> {{template "head.html"}} + </head> + <body> <b>composing</b><br> <br> <form action=/out method=post enctype=multipart/form-data> @@ -29,3 +34,5 @@ <label>Attachments: </label><input type=file name=files multiple><br> <input type=submit value=send> </form> + </body> +</html>
commit a98c9e1314fda90fb3460456f1646ce656c464ba Author: bmayer3 <bmayer@sibros.tech> Date: Mon Apr 24 14:05:40 2023 -0300 Moved email reading to interfaces * Improved pages diff --git a/www/inboxes.html b/www/inboxes.html index 3bbf0a6..7582762 100644 --- a/www/inboxes.html +++ b/www/inboxes.html @@ -1,12 +1,18 @@ +<!DOCTYPE html> +<html> +<head> {{template "head.html"}} - +</head> +<body> <h2>{{.Query.Get "inbox"}}</h2> + <a href="index.html">index</a>  <a href="compose.html?inbox={{.Query.Get "inbox"}}">compose</a> -<br><br> - {{range (.Mailer.Mailboxes (.Query.Get "inbox"))}} +<p> <a href="mails.html?inbox={{$.Query.Get "inbox"}}&subj={{.Title}}">{{.Title}}</a><br> - Updated: {{.LastMod.Format "Mon, 02 Jan 2006 15:04:05 MST"}}<br> - <br> + Updated: {{.LastMod.Format "Mon, 02 Jan 2006 15:04:05 MST"}} +</p> {{end}} +</body> +</html>
commit a98c9e1314fda90fb3460456f1646ce656c464ba Author: bmayer3 <bmayer@sibros.tech> Date: Mon Apr 24 14:05:40 2023 -0300 Moved email reading to interfaces * Improved pages diff --git a/www/index.html b/www/index.html index 5d17e43..c91b2fe 100644 --- a/www/index.html +++ b/www/index.html @@ -16,14 +16,13 @@ _ __ /_ __ \_ | / / _ \_ / </pre> </center> - -<a href=compose.html>compose</a><br> -<br> +<a href=compose.html>compose</a> {{range (.Mailer.Mailboxes ".")}} +<p> <a href="inboxes.html?inbox={{.Title}}">{{.Title}}</a><br> - Updated: {{.LastMod.Format "Mon, 02 Jan 2006 15:04:05 MST"}}<br> - <br> + Updated: {{.LastMod.Format "Mon, 02 Jan 2006 15:04:05 MST"}} +</p> {{end}} </body> </html>
commit a98c9e1314fda90fb3460456f1646ce656c464ba Author: bmayer3 <bmayer@sibros.tech> Date: Mon Apr 24 14:05:40 2023 -0300 Moved email reading to interfaces * Improved pages diff --git a/www/mails.html b/www/mails.html index c9a8f27..acbee54 100644 --- a/www/mails.html +++ b/www/mails.html @@ -1,18 +1,41 @@ +<!DOCTYPE html> +<html> + <head> {{template "head.html"}} + </head> + <body> <h2>{{.Query.Get "subj"}}</h2> + <a href="inboxes.html?inbox={{.Query.Get "inbox"}}">inbox</a>  -<a href="compose.html?inbox={{.Query.Get "inbox"}}&subj={{.Query.Get "subj"}}">compose</a><br> +<a href="compose.html?inbox={{.Query.Get "inbox"}}&subj={{.Query.Get "subj"}}">compose</a> {{$inbox := printf "%s/%s" (.Query.Get "inbox") (.Query.Get "subj")}} {{range (.Mailer.Mails $inbox)}} <p> - {{if eq ($.Query.Get "inbox") .From}}To: {{index .To 0}}{{else}}From: {{.From}}{{end}}<br> - Date: {{.Date.Format "Mon, 02 Jan 2006 15:04:05 MST"}}<br> - {{if .Cc}}Cc: .Cc<br>{{end}} + <details> + <summary> + {{if eq ($.Query.Get "inbox") .From}} + To: {{index .To 0}} + {{else}} + From: {{.From}} + {{end}}<br> + Date: {{.Date.Format "Mon, 02 Jan 2006 15:04:05 MST"}}<br> + {{if .Cc}}Cc: .Cc{{end}} + </summary> + <ul> + {{range $k, $vs := .Headers}} + <li>{{$k}}: {{$vs}}</li> + {{end}} + </ul> + </details> {{if .Attachments}} - Attachments:<br> + Attachments: + <ul> {{range .Attachments}} - <a href="data:{{.ContentType}};base64,{{.Data}}" download="{{.Name}}">{{.Name}}</a><br> + <li> + <a href="data:{{.ContentType}};base64,{{.Data}}" download="{{.Name}}">{{.Name}}</a> + </li> {{end}} + </ul> {{end}} {{if .Body}} <pre>{{.Body}}</pre> @@ -20,3 +43,5 @@ <a href="compose.html?inbox={{$.Query.Get "inbox"}}&subj={{.Subject}}&to={{.From}}">reply</a> </p> {{end}} + </body> +</html>