From f59ca1976a1075e9e8fdf1e5fcdb7cfc853493b8 Mon Sep 17 00:00:00 2001 From: Bobby <30593201+luciferreeves@users.noreply.github.com> Date: Mon, 29 Dec 2025 10:46:00 +0530 Subject: feat: Enhance email viewer with new UI actions, sender profile pictures, and raw header display. --- utils/format/html.go | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'utils/format') diff --git a/utils/format/html.go b/utils/format/html.go index d976cb8..60e2e85 100644 --- a/utils/format/html.go +++ b/utils/format/html.go @@ -7,18 +7,10 @@ import ( ) func SanitizeHTML(htmlContent string) string { - // Remove dangerous tags htmlContent = removeDangerousTags(htmlContent) - - // Remove inline event handlers htmlContent = removeEventHandlers(htmlContent) - - // Remove javascript: protocol htmlContent = removeJavascriptProtocol(htmlContent) - - // Sanitize styles htmlContent = sanitizeStyles(htmlContent) - return htmlContent } @@ -49,7 +41,6 @@ func removeJavascriptProtocol(html string) string { } func sanitizeStyles(html string) string { - // Remove dangerous CSS properties dangerousStyles := []string{"behavior", "expression", "binding", "import", "moz-binding"} for _, style := range dangerousStyles { @@ -127,6 +118,46 @@ func StripHTML(html string) string { return strings.TrimSpace(strings.Join(cleanLines, " ")) } +func HTMLToPlainText(htmlContent string) string { + text := htmlContent + + text = regexp.MustCompile(`(?i)]*>[\s\S]*?`).ReplaceAllString(text, "") + text = regexp.MustCompile(`(?i)]*>[\s\S]*?`).ReplaceAllString(text, "") + text = regexp.MustCompile(`(?i)]*>[\s\S]*?`).ReplaceAllString(text, "") + text = regexp.MustCompile(`(?i)]*>[\s\S]*?`).ReplaceAllString(text, "") + + text = regexp.MustCompile(`(?i)`).ReplaceAllString(text, "\n") + text = regexp.MustCompile(`(?i)

`).ReplaceAllString(text, "\n\n") + text = regexp.MustCompile(`(?i)`).ReplaceAllString(text, "\n") + text = regexp.MustCompile(`(?i)`).ReplaceAllString(text, "\n") + text = regexp.MustCompile(`(?i)`).ReplaceAllString(text, "\n\n") + text = regexp.MustCompile(`(?i)`).ReplaceAllString(text, "\n") + + text = regexp.MustCompile(`<[^>]+>`).ReplaceAllString(text, "") + + text = strings.ReplaceAll(text, " ", " ") + text = strings.ReplaceAll(text, "<", "<") + text = strings.ReplaceAll(text, ">", ">") + text = strings.ReplaceAll(text, "&", "&") + text = strings.ReplaceAll(text, """, "\"") + text = strings.ReplaceAll(text, "'", "'") + text = strings.ReplaceAll(text, "'", "'") + + text = regexp.MustCompile(`\n\s*\n\s*\n+`).ReplaceAllString(text, "\n\n") + text = regexp.MustCompile(`[ \t]+`).ReplaceAllString(text, " ") + + lines := strings.Split(text, "\n") + var cleanLines []string + for _, line := range lines { + trimmed := strings.TrimSpace(line) + if trimmed != "" { + cleanLines = append(cleanLines, trimmed) + } + } + + return strings.TrimSpace(strings.Join(cleanLines, "\n")) +} + func DecodeHTML(text string) string { return html.UnescapeString(text) } -- cgit v1.2.3