mirror of
https://github.com/axllent/mailpit.git
synced 2025-06-23 00:29:15 +02:00
Chore: Replace html2text modules with simplified internal function
The module microcosm-cc/bluemonday now requires Go v1.21 and is quite frankly an overkill as Mailpit only needs to convert HTML to a single line (no formatting).
This commit is contained in:
@ -3,6 +3,8 @@ package tools
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/axllent/mailpit/internal/tools/html2text"
|
||||
)
|
||||
|
||||
// CreateSnippet returns a message snippet. It will use the HTML version (if it exists)
|
||||
@ -12,17 +14,13 @@ func CreateSnippet(text, html string) string {
|
||||
html = strings.TrimSpace(html)
|
||||
limit := 200
|
||||
spaceRe := regexp.MustCompile(`\s+`)
|
||||
nlRe := regexp.MustCompile(`\r?\n`)
|
||||
|
||||
if text == "" && html == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if html != "" {
|
||||
data := nlRe.ReplaceAllString(stripHTML(html), " ")
|
||||
// replace \uFEFF with space, see https://github.com/golang/go/issues/42274#issuecomment-1017258184
|
||||
data = strings.ReplaceAll(data, string('\uFEFF'), " ")
|
||||
data = strings.TrimSpace(spaceRe.ReplaceAllString(data, " "))
|
||||
data := html2text.Strip(html, false)
|
||||
|
||||
if len(data) <= limit {
|
||||
return data
|
||||
|
Reference in New Issue
Block a user