1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-03-17 21:18:19 +02:00

Bugfix: Include HTML link text in search data

`<a href="https://example.com">search text</a>` now stores `search text https://example.com` in the database.

Resolves #30
This commit is contained in:
Ralph Slooten 2023-01-05 11:55:18 +13:00
parent acee53537c
commit d47eb09c54

View File

@ -37,7 +37,12 @@ func createSearchText(env *enmime.Envelope) string {
b.WriteString(env.GetHeader("To") + " ")
b.WriteString(env.GetHeader("Cc") + " ")
b.WriteString(env.GetHeader("Bcc") + " ")
h := strings.TrimSpace(html2text.HTML2Text(env.HTML))
h := strings.TrimSpace(
html2text.HTML2TextWithOptions(
env.HTML,
html2text.WithLinksInnerText(),
),
)
if h != "" {
b.WriteString(h + " ")
} else {
@ -56,7 +61,7 @@ func createSearchText(env *enmime.Envelope) string {
// CleanString removes unwanted characters from stored search text and search queries
func cleanString(str string) string {
// remove/replace new lines
re := regexp.MustCompile(`(\r?\n|\t|>|<|"|:|\,|;)`)
re := regexp.MustCompile(`(\r?\n|\t|>|<|"|\,|;)`)
str = re.ReplaceAllString(str, " ")
// remove duplicate whitespace and trim