This is the main dovel repository, it has the Go code to run dovel SMTP server.
Author: blmayer (bleemayer@gmail.com)
Date: Sun May 14 02:30:50 2023 -0300
Parent: 524ef2d
Improved move and delete
commit afdd85f38b30257e27cd6c5045b6e8e72c05bc9c Author: blmayer <bleemayer@gmail.com> Date: Sun May 14 02:30:50 2023 -0300 Improved move and delete diff --git a/cmd/dovel/main.go b/cmd/dovel/main.go index b1b963c..7cbf1ca 100644 --- a/cmd/dovel/main.go +++ b/cmd/dovel/main.go @@ -86,6 +86,7 @@ func main() { } http.HandleFunc(hand.Domain+"/", web.indexHandler()) http.HandleFunc(hand.Domain+"/move", web.moveHandler) + http.HandleFunc(hand.Domain+"/delete", web.deleteHandler) http.HandleFunc(hand.Domain+"/assets/", web.assetsHandler()) http.HandleFunc(hand.Domain+"/out", web.sendHandler()) }
commit afdd85f38b30257e27cd6c5045b6e8e72c05bc9c Author: blmayer <bleemayer@gmail.com> Date: Sun May 14 02:30:50 2023 -0300 Improved move and delete diff --git a/cmd/dovel/vault.go b/cmd/dovel/vault.go index b680ca4..fc9483b 100644 --- a/cmd/dovel/vault.go +++ b/cmd/dovel/vault.go @@ -11,6 +11,7 @@ type plainTextUser struct { Name string Mail string Password string + Config any } func (u plainTextUser) Email() string { @@ -25,6 +26,10 @@ func (u plainTextUser) Pass() string { return u.Password } +func (u plainTextUser) Settings() any { + return u.Config +} + type plainTextVault struct { Users []plainTextUser }
commit afdd85f38b30257e27cd6c5045b6e8e72c05bc9c Author: blmayer <bleemayer@gmail.com> Date: Sun May 14 02:30:50 2023 -0300 Improved move and delete diff --git a/cmd/dovel/web.go b/cmd/dovel/web.go index 117321d..57d261a 100644 --- a/cmd/dovel/web.go +++ b/cmd/dovel/web.go @@ -36,9 +36,11 @@ func (h webHandler) indexHandler() http.HandlerFunc { struct { Query url.Values Mailer interfaces.Mailer + User interfaces.User }{ r.URL.Query(), h.mailer, + h.vault.GetUser(user), }, ) if err != nil { @@ -62,8 +64,29 @@ func (h webHandler) moveHandler(w http.ResponseWriter, r *http.Request) { return } - err := h.mailer.Move(id, to) - if id == "" || to == "" { + if err := h.mailer.Move(id, to); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + http.Redirect(w, r, "/", http.StatusFound) +} + +func (h webHandler) deleteHandler(w http.ResponseWriter, r *http.Request) { + user, pass, _ := r.BasicAuth() + if user == "" || !h.vault.Validate(user, pass) { + w.Header().Add("WWW-Authenticate", "Basic") + http.Error(w, "wrong auth", http.StatusUnauthorized) + return + } + + id := r.URL.Query().Get("id") + if id == "" { + http.Error(w, "empty id", http.StatusBadRequest) + return + } + + if err := h.mailer.Delete(id); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return }
commit afdd85f38b30257e27cd6c5045b6e8e72c05bc9c Author: blmayer <bleemayer@gmail.com> Date: Sun May 14 02:30:50 2023 -0300 Improved move and delete diff --git a/index.html b/index.html index fcb8293..98e0ae8 100644 --- a/index.html +++ b/index.html @@ -92,9 +92,9 @@ _ __ /_ __ \_ | / / _ \_ / <ul> <li><s>Support DKIM.</s></li> <li><s>Multiple inboxes.</s></li> + <li><s>Support moving and deleting email on web.</s></li> <li>PGP support.</li> <li>Multiple users.</li> - <li>Support moving and deleting email on web.</li> <li>Implement mailing lists behaviour.</li> </ul>
commit afdd85f38b30257e27cd6c5045b6e8e72c05bc9c Author: blmayer <bleemayer@gmail.com> Date: Sun May 14 02:30:50 2023 -0300 Improved move and delete diff --git a/interfaces/main.go b/interfaces/main.go index 8d8a066..3b58c3d 100644 --- a/interfaces/main.go +++ b/interfaces/main.go @@ -19,6 +19,7 @@ type User interface { Email() string Login() string Pass() string + Settings() any } type Vault interface {
commit afdd85f38b30257e27cd6c5045b6e8e72c05bc9c Author: blmayer <bleemayer@gmail.com> Date: Sun May 14 02:30:50 2023 -0300 Improved move and delete diff --git a/www/mails.html b/www/mails.html index 08d419d..b457664 100644 --- a/www/mails.html +++ b/www/mails.html @@ -41,7 +41,19 @@ <pre>{{.Body}}</pre> {{end}} <a href="compose.html?inbox={{$.Query.Get "inbox"}}&subj={{.Subject}}&to={{.From}}">reply</a> - <a href="delete.html?id={{.ID}}">delete</a> + <form action=delete> + <input type=hidden name=id value="{{.ID}}"> + <input type=submit value=delete> + </form> + <details> + <summary>move</summary> + <form action=/move> + <input name=to type=select list=folders><br> + <datalist id=folders> + </datalist> + <input type=submit value=move> + <form> + </details> </p> {{end}} </body>