mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 21:09:39 +00:00
75 lines
1.6 KiB
Plaintext
75 lines
1.6 KiB
Plaintext
package web_server
|
|
|
|
import (
|
|
"github.com/russross/blackfriday/v2"
|
|
"github.com/microcosm-cc/bluemonday"
|
|
"github.com/GRFreire/nthmail/pkg/mail_utils"
|
|
)
|
|
|
|
templ mail_body_comp(rcpt_addr string, m mail_utils.Mail_obj, policy *bluemonday.Policy) {
|
|
<!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"/>
|
|
@styles()
|
|
</head>
|
|
<body class="mail">
|
|
@header(rcpt_addr)
|
|
<div class="mail-header">
|
|
<div class="mail-from">
|
|
<span>From: </span>
|
|
<h3>{ m.From }</h3>
|
|
</div>
|
|
<div class="mail-subject">
|
|
<span>Subject: </span>
|
|
<h3>{ m.Subject }</h3>
|
|
</div>
|
|
<div class="mail-date">
|
|
<span>At: </span>
|
|
<h3>{ m.Date.Format("15:04:05 02/01/2006") }</h3>
|
|
</div>
|
|
</div>
|
|
<main>
|
|
@mime_type(m.Body[m.PreferedBodyIndex], policy)
|
|
</main>
|
|
@footer()
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
templ mime_type(b mail_utils.Mail_body, policy *bluemonday.Policy) {
|
|
switch b.MimeType {
|
|
case mail_utils.Html:
|
|
@body_html(b.Data, policy)
|
|
case mail_utils.Markdown:
|
|
@body_markdown(b.Data)
|
|
case mail_utils.PlainText:
|
|
@body_plain(b.Data)
|
|
default:
|
|
@body_plain(b.Data)
|
|
}
|
|
}
|
|
|
|
templ body_plain(s string) {
|
|
<div class="content-text">
|
|
<pre>
|
|
{ s }
|
|
</pre>
|
|
</div>
|
|
}
|
|
|
|
templ body_html(s string, policy *bluemonday.Policy) {
|
|
<div class="content-html">
|
|
@templ.Raw(policy.Sanitize(s))
|
|
</div>
|
|
}
|
|
|
|
templ body_markdown(s string) {
|
|
<div class="content-md">
|
|
{ string(blackfriday.Run([]byte(s))) }
|
|
</div>
|
|
}
|