From e291d408336f7ddaf5618128a9b34a856c0b9c84 Mon Sep 17 00:00:00 2001 From: Max Magorsch Date: Tue, 23 Jun 2020 19:24:20 +0000 Subject: Decode subjects correctly Signed-off-by: Max Magorsch --- pkg/models/message.go | 9 +++++++++ web/templates/home/home.tmpl | 4 ++-- web/templates/list/messages.tmpl | 2 +- web/templates/list/threads.tmpl | 2 +- web/templates/message/show.tmpl | 2 +- web/templates/popular/threads.tmpl | 2 +- web/templates/search/searchresults.tmpl | 2 +- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/models/message.go b/pkg/models/message.go index 25b2966..70c4e8f 100644 --- a/pkg/models/message.go +++ b/pkg/models/message.go @@ -1,6 +1,7 @@ package models import ( + "mime" "net/mail" "strings" "time" @@ -80,6 +81,14 @@ func (m Message) GetAuthorName() string { return addr.Name } +func (m Message) GetSubject() string { + header, err := new(mime.WordDecoder).DecodeHeader(m.Subject) + if err == nil { + return header + } + return m.Subject +} + func (m Message) GetMessageId() string { messageId := m.MessageId messageId = strings.ReplaceAll(messageId, "<", "") diff --git a/web/templates/home/home.tmpl b/web/templates/home/home.tmpl index afef5cc..a46d3fc 100644 --- a/web/templates/home/home.tmpl +++ b/web/templates/home/home.tmpl @@ -45,7 +45,7 @@

Recent Popular Threads

{{range .PopularThreads}} -

{{.Subject}}

+

{{.GetSubject}}

{{end}}
@@ -87,7 +87,7 @@ {{$listName:=.Name}} {{range .Messages}} - {{.Subject}} + {{.GetSubject}} {{.GetAuthorName}} {{end}} diff --git a/web/templates/list/messages.tmpl b/web/templates/list/messages.tmpl index fff6a53..28973b4 100644 --- a/web/templates/list/messages.tmpl +++ b/web/templates/list/messages.tmpl @@ -28,7 +28,7 @@ {{range .Messages}} - {{.Subject}} + {{.GetSubject}} {{.GetAuthorName}} {{.Date.Format "Mon, 2 Jan 2006 15:04:05"}} diff --git a/web/templates/list/threads.tmpl b/web/templates/list/threads.tmpl index 933417a..1895d9c 100644 --- a/web/templates/list/threads.tmpl +++ b/web/templates/list/threads.tmpl @@ -28,7 +28,7 @@ {{range .Messages}} - {{.Subject}} + {{.GetSubject}} {{.GetAuthorName}} {{.Date.Format "Mon, 2 Jan 2006 15:04:05"}} diff --git a/web/templates/message/show.tmpl b/web/templates/message/show.tmpl index 76ffdf4..390fe0a 100644 --- a/web/templates/message/show.tmpl +++ b/web/templates/message/show.tmpl @@ -28,7 +28,7 @@ Subject: - {{.Message.Subject}} + {{.Message.GetSubject}} Date: diff --git a/web/templates/popular/threads.tmpl b/web/templates/popular/threads.tmpl index 4dfcbbc..84bc6d6 100644 --- a/web/templates/popular/threads.tmpl +++ b/web/templates/popular/threads.tmpl @@ -16,7 +16,7 @@ {{range .}} - {{.Subject}} + {{.GetSubject}} {{end}} diff --git a/web/templates/search/searchresults.tmpl b/web/templates/search/searchresults.tmpl index 19ed5e4..df81429 100644 --- a/web/templates/search/searchresults.tmpl +++ b/web/templates/search/searchresults.tmpl @@ -28,7 +28,7 @@ {{range .Messages}} - {{.Subject}} + {{.GetSubject}} {{.GetAuthorName}} {{.Date.Format "Mon, 2 Jan 2006 15:04:05"}} -- cgit v1.2.3-65-gdbad