Compare commits
2 Commits
b19666211c
...
7c3e978b3a
Author | SHA1 | Date | |
---|---|---|---|
7c3e978b3a | |||
f777cf6d11 |
@ -129,11 +129,3 @@ make release
|
||||
## Licence
|
||||
|
||||
AGPL-3.0
|
||||
|
||||
|
||||
### Envoyer un email de test
|
||||
outil : swaks
|
||||
|
||||
```
|
||||
swaks -t test@test.com -s localhost:2525 -f test@test.com -au fakesmtp -ap fakesmtp --add-header "Content-Type: text/html" --h-Subject "Sujet de message" --body "$(cat sample.txt)"
|
||||
```
|
||||
|
@ -1,7 +1,7 @@
|
||||
{{define "title"}}Email - FakeSMTP{{end}}
|
||||
{{define "header_buttons"}}
|
||||
<button class="button is-danger"
|
||||
data-controller="restful"
|
||||
data-controller="restful"
|
||||
data-restful-endpoint="{{ .BaseURL }}/emails/{{ .Email.ID }}"
|
||||
data-restful-method="DELETE"
|
||||
data-restful-redirect="{{ .BaseURL }}/">
|
||||
@ -35,24 +35,16 @@
|
||||
<div data-controller="tabs">
|
||||
<div class="tabs">
|
||||
<ul>
|
||||
<li data-action="click->tabs#openTab" data-target="tabs.tab" data-tabs-name="mail" {{if .Email.HTML}}class="is-active"{{end}}><a>Mail</a></li>
|
||||
<li data-action="click->tabs#openTab" data-target="tabs.tab" data-tabs-name="html" ><a>HTML</a></li>
|
||||
<li data-action="click->tabs#openTab" data-target="tabs.tab" data-tabs-name="html" {{if .Email.HTML}}class="is-active"{{end}}><a>HTML</a></li>
|
||||
<li data-action="click->tabs#openTab" data-target="tabs.tab" data-tabs-name="text" {{if not .Email.HTML}}class="is-active"{{end}}><a>Text</a></li>
|
||||
<li data-action="click->tabs#openTab" data-target="tabs.tab" data-tabs-name="headers"><a>Headers</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<iframe data-target="tabs.tabContent" data-tabs-for="mail"
|
||||
<iframe data-target="tabs.tabContent" data-tabs-for="html"
|
||||
frameborder="0"
|
||||
data-controller="iframe"
|
||||
data-action="load->iframe#onLoad"
|
||||
style="width:100%;{{if not .Email.HTML}}display:none;{{end}}"
|
||||
src="{{ .BaseURL }}/emails/{{ .Email.ID }}/mail">
|
||||
</iframe>
|
||||
<iframe data-target="tabs.tabContent" data-tabs-for="html"
|
||||
frameborder="0"
|
||||
data-controller="iframe"
|
||||
data-action="load->iframe#onLoad"
|
||||
style="width:100%;{{if not .Email.HTML}}display:none;{{end}}"
|
||||
style="width:100%;{{if not .Email.HTML}}display:none;{{end}}"
|
||||
src="{{ .BaseURL }}/emails/{{ .Email.ID }}/html">
|
||||
</iframe>
|
||||
<div data-target="tabs.tabContent" data-tabs-for="text" style="{{if .Email.HTML}}display:none;{{end}}width:100%;overflow:hidden;">
|
||||
|
@ -5,12 +5,13 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
|
||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/command"
|
||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/model"
|
||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/query"
|
||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/storm"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/pkg/errors"
|
||||
"gitlab.com/wpetit/goweb/cqrs"
|
||||
"gitlab.com/wpetit/goweb/middleware/container"
|
||||
@ -50,42 +51,6 @@ func serveEmailPage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func serveEmailContent(w http.ResponseWriter, r *http.Request) {
|
||||
emailID, err := getEmailID(r)
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
|
||||
email, err := openEmail(ctx, emailID)
|
||||
if err != nil {
|
||||
if errors.Is(err, storm.ErrNotFound) {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
panic(errors.Wrap(err, "could not open email"))
|
||||
}
|
||||
|
||||
html := email.HTML
|
||||
|
||||
if html == "" {
|
||||
http.Error(w, http.StatusText(http.StatusNoContent), http.StatusNoContent)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
policy := bluemonday.UGCPolicy()
|
||||
sanitizedHTML := policy.Sanitize(email.HTML)
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(sanitizedHTML))
|
||||
}
|
||||
|
||||
func serveEmailHTMLContent(w http.ResponseWriter, r *http.Request) {
|
||||
emailID, err := getEmailID(r)
|
||||
if err != nil {
|
||||
@ -115,7 +80,10 @@ func serveEmailHTMLContent(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
sanitizedHTML := email.HTML
|
||||
policy := bluemonday.UGCPolicy()
|
||||
policy.AllowAttrs("style", "color", "bgcolor").OnElements("h1", "h2", "h3", "h4", "h5", "h6", "p", "ul", "ol", "li", "a", "br", "strong", "em", "i", "b", "u", "span", "div", "table", "thead", "tbody", "tr", "th", "td", "img")
|
||||
|
||||
sanitizedHTML := policy.Sanitize(email.HTML)
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
w.Write([]byte(sanitizedHTML))
|
||||
|
@ -12,7 +12,6 @@ func Mount(r *chi.Mux, config *config.Config) error {
|
||||
r.Get("/", serveInboxPage)
|
||||
r.Delete("/emails", handleClearInbox)
|
||||
r.Get("/emails/{id}", serveEmailPage)
|
||||
r.Get("/emails/{id}/mail", serveEmailContent)
|
||||
r.Get("/emails/{id}/html", serveEmailHTMLContent)
|
||||
r.Get("/emails/{id}/attachments/{attachmendIndex}", serveEmailAttachment)
|
||||
r.Delete("/emails/{id}", handleEmailDelete)
|
||||
|
Loading…
x
Reference in New Issue
Block a user