fix(app): 重建仅含 HTML 邮件摘要

- 在迁移流程中新增仅含 HTML 消息摘要重建,修正旧数据中摘要保留样式内容的问题。
- 扩展 `snippetFrom` 的清理逻辑,过滤 `style`、`script`、`head`、`title`、`noscript` 等非内容标签。
- 补充相关测试,覆盖样式内容被剔除后的摘要重建行为。
This commit is contained in:
LanQin_
2026-06-24 17:34:41 +08:00
parent 2a572bf13a
commit 947e3ad248
3 changed files with 86 additions and 0 deletions
+2
View File
@@ -53,6 +53,7 @@ func (p *HTMLPolicy) Sanitize(s string) string {
}
var emailStyleTagRe = regexp.MustCompile(`(?is)<style\b([^>]*)>(.*?)</style>`)
var htmlNonContentTagRe = regexp.MustCompile(`(?is)<(style|script|head|title|noscript)\b[^>]*>.*?</\s*(style|script|head|title|noscript)\s*>`)
func extractSafeEmailStyles(value string) ([]string, string) {
styles := []string{}
@@ -241,6 +242,7 @@ func snippetFrom(text, html string) string {
}
func stripTags(s string) string {
s = htmlNonContentTagRe.ReplaceAllString(s, " ")
var b strings.Builder
inTag := false
for _, r := range s {