mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 21:09:39 +00:00
This commits adds support for rendering email in text/html, text/markdown and text/plain inside a MIME/multipart mail. Bluemonday was added as a dependency and initialized but it is still not used because the styling of the email is "discarted" too much. But this needs to be fixed before going to production.
85 lines
1.6 KiB
Plaintext
85 lines
1.6 KiB
Plaintext
package main
|
|
|
|
import (
|
|
"github.com/russross/blackfriday/v2"
|
|
)
|
|
|
|
templ inbox_body(rcpt_addr string, ms []mail_obj) {
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8"/>
|
|
<title>nthmail.xyz</title>
|
|
<meta name="viewport" content="width=device-width,initial-scale=1"/>
|
|
<meta name="description" content="A temporary mail service"/>
|
|
</head>
|
|
<body>
|
|
<h1>Emails for { rcpt_addr }:</h1>
|
|
<ul>
|
|
for _, m := range ms {
|
|
<li>
|
|
@mail_comp(m)
|
|
</li>
|
|
}
|
|
</ul>
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
templ mail_comp(m mail_obj) {
|
|
<h3>From: { m.From } at { m.Date }</h3>
|
|
if m.To != "" {
|
|
<h3>To: { m.To }</h3>
|
|
}
|
|
if m.Bcc != "" {
|
|
<h3>Bcc: { m.Bcc }</h3>
|
|
}
|
|
<h3>Subject: { m.Subject }</h3>
|
|
if m.MediaType == NotMultipart {
|
|
for _, b := range m.Body {
|
|
@body_plain(b.Data)
|
|
}
|
|
} else {
|
|
if m.MediaType == Mixed {
|
|
for _, b := range m.Body {
|
|
switch b.MimeType {
|
|
case PlainText:
|
|
@body_plain(b.Data)
|
|
case Html:
|
|
@body_html(b.Data)
|
|
case Markdown:
|
|
@body_plain(b.Data)
|
|
default:
|
|
@body_plain(b.Data)
|
|
}
|
|
}
|
|
} else {
|
|
switch m.Body[m.PreferedBodyIndex].MimeType {
|
|
case PlainText:
|
|
@body_plain(m.Body[m.PreferedBodyIndex].Data)
|
|
case Html:
|
|
@body_html(m.Body[m.PreferedBodyIndex].Data)
|
|
case Markdown:
|
|
@body_markdown(m.Body[m.PreferedBodyIndex].Data)
|
|
default:
|
|
@body_plain(m.Body[m.PreferedBodyIndex].Data)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
templ body_plain(s string) {
|
|
<p>{ s }</p>
|
|
}
|
|
|
|
templ body_html(s string) {
|
|
<p>
|
|
@templ.Raw(s)
|
|
</p>
|
|
}
|
|
|
|
templ body_markdown(s string) {
|
|
@body_html(string(blackfriday.Run([]byte(s))))
|
|
)
|
|
}
|