add tab to render full html
This commit is contained in:
parent
888ff2ec47
commit
213f92b163
@ -129,3 +129,11 @@ make release
|
|||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
AGPL-3.0
|
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 "title"}}Email - FakeSMTP{{end}}
|
||||||
{{define "header_buttons"}}
|
{{define "header_buttons"}}
|
||||||
<button class="button is-danger"
|
<button class="button is-danger"
|
||||||
data-controller="restful"
|
data-controller="restful"
|
||||||
data-restful-endpoint="{{ .BaseURL }}/emails/{{ .Email.ID }}"
|
data-restful-endpoint="{{ .BaseURL }}/emails/{{ .Email.ID }}"
|
||||||
data-restful-method="DELETE"
|
data-restful-method="DELETE"
|
||||||
data-restful-redirect="{{ .BaseURL }}/">
|
data-restful-redirect="{{ .BaseURL }}/">
|
||||||
@ -35,16 +35,24 @@
|
|||||||
<div data-controller="tabs">
|
<div data-controller="tabs">
|
||||||
<div class="tabs">
|
<div class="tabs">
|
||||||
<ul>
|
<ul>
|
||||||
<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="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="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="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>
|
<li data-action="click->tabs#openTab" data-target="tabs.tab" data-tabs-name="headers"><a>Headers</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<iframe data-target="tabs.tabContent" data-tabs-for="html"
|
<iframe data-target="tabs.tabContent" data-tabs-for="mail"
|
||||||
frameborder="0"
|
frameborder="0"
|
||||||
data-controller="iframe"
|
data-controller="iframe"
|
||||||
data-action="load->iframe#onLoad"
|
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 }}/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}}"
|
||||||
src="{{ .BaseURL }}/emails/{{ .Email.ID }}/html">
|
src="{{ .BaseURL }}/emails/{{ .Email.ID }}/html">
|
||||||
</iframe>
|
</iframe>
|
||||||
<div data-target="tabs.tabContent" data-tabs-for="text" style="{{if .Email.HTML}}display:none;{{end}}width:100%;overflow:hidden;">
|
<div data-target="tabs.tabContent" data-tabs-for="text" style="{{if .Email.HTML}}display:none;{{end}}width:100%;overflow:hidden;">
|
||||||
|
@ -5,13 +5,12 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/microcosm-cc/bluemonday"
|
|
||||||
|
|
||||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/command"
|
"forge.cadoles.com/Cadoles/fake-smtp/internal/command"
|
||||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/model"
|
"forge.cadoles.com/Cadoles/fake-smtp/internal/model"
|
||||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/query"
|
"forge.cadoles.com/Cadoles/fake-smtp/internal/query"
|
||||||
"forge.cadoles.com/Cadoles/fake-smtp/internal/storm"
|
"forge.cadoles.com/Cadoles/fake-smtp/internal/storm"
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/microcosm-cc/bluemonday"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gitlab.com/wpetit/goweb/cqrs"
|
"gitlab.com/wpetit/goweb/cqrs"
|
||||||
"gitlab.com/wpetit/goweb/middleware/container"
|
"gitlab.com/wpetit/goweb/middleware/container"
|
||||||
@ -51,7 +50,7 @@ func serveEmailPage(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveEmailHTMLContent(w http.ResponseWriter, r *http.Request) {
|
func serveEmailContent(w http.ResponseWriter, r *http.Request) {
|
||||||
emailID, err := getEmailID(r)
|
emailID, err := getEmailID(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
@ -87,6 +86,41 @@ func serveEmailHTMLContent(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write([]byte(sanitizedHTML))
|
w.Write([]byte(sanitizedHTML))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serveEmailHTMLContent(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
|
||||||
|
}
|
||||||
|
|
||||||
|
sanitizedHTML := email.HTML
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "text/html")
|
||||||
|
w.Write([]byte(sanitizedHTML))
|
||||||
|
}
|
||||||
|
|
||||||
func serveEmailAttachment(w http.ResponseWriter, r *http.Request) {
|
func serveEmailAttachment(w http.ResponseWriter, r *http.Request) {
|
||||||
emailID, err := getEmailID(r)
|
emailID, err := getEmailID(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12,6 +12,7 @@ func Mount(r *chi.Mux, config *config.Config) error {
|
|||||||
r.Get("/", serveInboxPage)
|
r.Get("/", serveInboxPage)
|
||||||
r.Delete("/emails", handleClearInbox)
|
r.Delete("/emails", handleClearInbox)
|
||||||
r.Get("/emails/{id}", serveEmailPage)
|
r.Get("/emails/{id}", serveEmailPage)
|
||||||
|
r.Get("/emails/{id}/mail", serveEmailContent)
|
||||||
r.Get("/emails/{id}/html", serveEmailHTMLContent)
|
r.Get("/emails/{id}/html", serveEmailHTMLContent)
|
||||||
r.Get("/emails/{id}/attachments/{attachmendIndex}", serveEmailAttachment)
|
r.Get("/emails/{id}/attachments/{attachmendIndex}", serveEmailAttachment)
|
||||||
r.Delete("/emails/{id}", handleEmailDelete)
|
r.Delete("/emails/{id}", handleEmailDelete)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user