nthmail/pkg/web_server/mail.templ
Guilherme Rugai Freire 48e7b5a9a5
integrate web and mail server
now, there is only one binary that starts both servers,
making them use the same SQL connection.

this commit also added some `defer tx.Commit()` to ensure
all the transactions were closed
2024-07-10 16:56:46 -03:00

73 lines
1.4 KiB
Plaintext

package web_server
import (
"github.com/russross/blackfriday/v2"
"github.com/GRFreire/nthmail/pkg/mail_utils"
)
templ mail_body_comp(rcpt_addr string, m mail_utils.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"/>
@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])
</main>
</body>
</html>
}
templ mime_type(b mail_utils.Mail_body) {
switch b.MimeType {
case mail_utils.Html:
@body_html(b.Data)
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) {
<div class="content-html">
@templ.Raw(s)
</div>
}
templ body_markdown(s string) {
<div class="content-md">
{ string(blackfriday.Run([]byte(s))) }
</div>
}