nthmail/cmd/web_server/mail.templ
2024-03-18 15:47:15 -03:00

55 lines
967 B
Plaintext

package main
import (
"github.com/russross/blackfriday/v2"
)
templ mail_body_comp(rcpt_addr string, m 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>
<header>
<h3>{m.Subject}</h3>
<h3>{m.From}</h3>
</header>
<main>
@mime_type(m.Body[m.PreferedBodyIndex])
</main>
</body>
</html>
}
templ mime_type(b mail_body) {
switch b.MimeType {
case Html:
@body_html(b.Data)
case Markdown:
@body_markdown(b.Data)
case PlainText:
@body_plain(b.Data)
default:
@body_plain(b.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))))
)
}