This is the main dovel repository, it has the Go code to run dovel SMTP server.
Author: blmayer (bleemayer@gmail.com)
Date: Thu May 11 15:34:38 2023 -0300
Parent: 78c3a26
Added move and delete operations
commit 524ef2daf10ef1772f9ffb8b072e542e313aba2a Author: blmayer <bleemayer@gmail.com> Date: Thu May 11 15:34:38 2023 -0300 Added move and delete operations diff --git a/cmd/dovel/main.go b/cmd/dovel/main.go index 6f37484..b1b963c 100644 --- a/cmd/dovel/main.go +++ b/cmd/dovel/main.go @@ -85,6 +85,7 @@ func main() { panic(err) } http.HandleFunc(hand.Domain+"/", web.indexHandler()) + http.HandleFunc(hand.Domain+"/move", web.moveHandler) http.HandleFunc(hand.Domain+"/assets/", web.assetsHandler()) http.HandleFunc(hand.Domain+"/out", web.sendHandler()) }
commit 524ef2daf10ef1772f9ffb8b072e542e313aba2a Author: blmayer <bleemayer@gmail.com> Date: Thu May 11 15:34:38 2023 -0300 Added move and delete operations diff --git a/cmd/dovel/web.go b/cmd/dovel/web.go index 3db1fed..117321d 100644 --- a/cmd/dovel/web.go +++ b/cmd/dovel/web.go @@ -47,6 +47,30 @@ func (h webHandler) indexHandler() http.HandlerFunc { } } +func (h webHandler) moveHandler(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") + to := r.URL.Query().Get("to") + if id == "" || to == "" { + http.Error(w, "empty parameters", http.StatusBadRequest) + return + } + + err := h.mailer.Move(id, to) + if id == "" || to == "" { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + http.Redirect(w, r, "/", http.StatusFound) +} + func (h webHandler) assetsHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, path.Join(h.assetsPath, r.URL.Path[1:]))
commit 524ef2daf10ef1772f9ffb8b072e542e313aba2a Author: blmayer <bleemayer@gmail.com> Date: Thu May 11 15:34:38 2023 -0300 Added move and delete operations diff --git a/interfaces/file/file.go b/interfaces/file/file.go index cbbf502..9dfc7d4 100644 --- a/interfaces/file/file.go +++ b/interfaces/file/file.go @@ -162,8 +162,8 @@ func (f FileHandler) Send(mail interfaces.Email) error { } mail.Raw = payload.Bytes() - // dns mx for email for _, to := range mail.To { + // dns mx for email addr := strings.Split(to, "@") mxs, err := net.LookupMX(addr[1]) if err != nil { @@ -274,3 +274,17 @@ func (f FileHandler) Mail(file string) (interfaces.Email, error) { return interfaces.ToEmail(mail), nil } + +// Move is used to move messages between folders. The id parameter +// is the message id to be moved and to is the destination folder. +// Root is added automatically. +func (f FileHandler) Move(id, to string) error { + return os.Rename(path.Join(f.root, id), path.Join(f.root, to, "/")) +} + +// Delete is used to delete messages. The id parameter +// is the message id to be deleted. +// Root is added automatically. +func (f FileHandler) Delete(id string) error { + return os.Remove(path.Join(f.root, id)) +}
commit 524ef2daf10ef1772f9ffb8b072e542e313aba2a Author: blmayer <bleemayer@gmail.com> Date: Thu May 11 15:34:38 2023 -0300 Added move and delete operations diff --git a/interfaces/gwi/gwi.go b/interfaces/gwi/gwi.go index 87ab1ab..a529625 100644 --- a/interfaces/gwi/gwi.go +++ b/interfaces/gwi/gwi.go @@ -32,6 +32,7 @@ import ( // body starts with key! then the command key is run. type GWIHandler struct { root string + notify bool Commands map[string]func(email interfaces.Email) error domain string privateKey crypto.Signer @@ -335,3 +336,17 @@ func (g GWIHandler) Mail(file string) (interfaces.Email, error) { } return email, nil } + +// Move is used to move messages between folders. The id parameter +// is the message id to be moved and to is the destination folder. +// Root is added automatically. +func (g GWIHandler) Move(id, to string) error { + return os.Rename(path.Join(g.root, id), path.Join(g.root, to, "/")) +} + +// Delete is used to delete messages. The id parameter +// is the message id to be deleted. +// Root is added automatically. +func (g GWIHandler) Delete(id string) error { + return os.Remove(path.Join(g.root, id)) +}
commit 524ef2daf10ef1772f9ffb8b072e542e313aba2a Author: blmayer <bleemayer@gmail.com> Date: Thu May 11 15:34:38 2023 -0300 Added move and delete operations diff --git a/interfaces/main.go b/interfaces/main.go index 56d828e..8d8a066 100644 --- a/interfaces/main.go +++ b/interfaces/main.go @@ -106,4 +106,6 @@ type Mailer interface { Mailboxes(folder string) ([]Mailbox, error) Mails(folder string) ([]Email, error) Mail(file string) (Email, error) + Move(id, to string) error + Delete(id string) error }
commit 524ef2daf10ef1772f9ffb8b072e542e313aba2a Author: blmayer <bleemayer@gmail.com> Date: Thu May 11 15:34:38 2023 -0300 Added move and delete operations diff --git a/www/mails.html b/www/mails.html index acbee54..08d419d 100644 --- a/www/mails.html +++ b/www/mails.html @@ -41,6 +41,7 @@ <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> </p> {{end}} </body>