mirror of
https://github.com/ivabus/pop
synced 2024-11-10 02:25:19 +03:00
feat/unsafe html (#11)
* add unsafe html render and plugins * small env fix * update UNSAFE_HTML env Co-authored-by: Maas Lalani <maas@lalani.dev> --------- Co-authored-by: Maas Lalani <maas@lalani.dev>
This commit is contained in:
parent
85b1f54563
commit
f8dfdafcd2
16
email.go
16
email.go
|
@ -9,6 +9,8 @@ import (
|
|||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/resendlabs/resend-go"
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
renderer "github.com/yuin/goldmark/renderer/html"
|
||||
)
|
||||
|
||||
const TO_SEPARATOR = ","
|
||||
|
@ -41,7 +43,21 @@ func sendEmail(to []string, from, subject, body string, paths []string) error {
|
|||
|
||||
html := bytes.NewBufferString("")
|
||||
// If the conversion fails, we'll simply send the plain-text body.
|
||||
if unsafe {
|
||||
markdown := goldmark.New(
|
||||
goldmark.WithRendererOptions(
|
||||
renderer.WithUnsafe(),
|
||||
),
|
||||
goldmark.WithExtensions(
|
||||
extension.Strikethrough,
|
||||
extension.Table,
|
||||
extension.Linkify,
|
||||
),
|
||||
)
|
||||
_ = markdown.Convert([]byte(body), html)
|
||||
} else {
|
||||
_ = goldmark.Convert([]byte(body), html)
|
||||
}
|
||||
|
||||
request := &resend.SendEmailRequest{
|
||||
From: from,
|
||||
|
|
4
main.go
4
main.go
|
@ -15,6 +15,7 @@ import (
|
|||
)
|
||||
|
||||
const RESEND_API_KEY = "RESEND_API_KEY"
|
||||
const UNSAFE_HTML = "POP_UNSAFE_HTML"
|
||||
const POP_FROM = "POP_FROM"
|
||||
const POP_SIGNATURE = "POP_SIGNATURE"
|
||||
|
||||
|
@ -25,6 +26,7 @@ var (
|
|||
body string
|
||||
attachments []string
|
||||
preview bool
|
||||
unsafe bool
|
||||
signature string
|
||||
)
|
||||
|
||||
|
@ -151,6 +153,8 @@ func init() {
|
|||
rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender "+commentStyle.Render("($"+POP_FROM+")"))
|
||||
rootCmd.Flags().StringVarP(&subject, "subject", "s", "", "Email's subject")
|
||||
rootCmd.Flags().BoolVarP(&preview, "preview", "p", false, "Whether to preview the email before sending")
|
||||
envUnsafe := os.Getenv(UNSAFE_HTML) == "true"
|
||||
rootCmd.Flags().BoolVarP(&unsafe, "unsafe", "u", envUnsafe, "Whether to allow unsafe HTML in the email body, also enable some extra markdown features (Experimental)")
|
||||
envSignature := os.Getenv("POP_SIGNATURE")
|
||||
rootCmd.Flags().StringVarP(&signature, "signature", "x", envSignature, "Signature to display at the end of the email. "+commentStyle.Render("($"+POP_SIGNATURE+")"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue