mirror of
https://github.com/GRFreire/nthmail.git
synced 2026-01-09 21:09:39 +00:00
- Move mail functions to its own packages; - Move bigger router functions to its own functions, and separate router creation from main function; - Edit the algorithm that choses the format will be chosen with regards to format preference to a simples one.
56 lines
1.0 KiB
Plaintext
56 lines
1.0 KiB
Plaintext
package main
|
|
|
|
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"/>
|
|
</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_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) {
|
|
<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))))
|
|
)
|
|
}
|