aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-23 19:24:20 +0000
committerMax Magorsch <arzano@gentoo.org>2020-06-23 19:24:20 +0000
commite291d408336f7ddaf5618128a9b34a856c0b9c84 (patch)
tree072ca4d9342533a590b6d283369613330ac3e978
parentImprove link to popular threads (diff)
downloadarchives-e291d408336f7ddaf5618128a9b34a856c0b9c84.tar.gz
archives-e291d408336f7ddaf5618128a9b34a856c0b9c84.tar.bz2
archives-e291d408336f7ddaf5618128a9b34a856c0b9c84.zip
Decode subjects correctly
Signed-off-by: Max Magorsch <arzano@gentoo.org>
-rw-r--r--pkg/models/message.go9
-rw-r--r--web/templates/home/home.tmpl4
-rw-r--r--web/templates/list/messages.tmpl2
-rw-r--r--web/templates/list/threads.tmpl2
-rw-r--r--web/templates/message/show.tmpl2
-rw-r--r--web/templates/popular/threads.tmpl2
-rw-r--r--web/templates/search/searchresults.tmpl2
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 @@
<div class="mx-auto text-center">
<p class="mb-1"><a class="text-muted" href="/popular"><b>Recent Popular Threads</b></a></p>
{{range .PopularThreads}}
- <p class="mb-1"><a href="/{{.List}}/message/{{.Id}}" class="text-muted">{{.Subject}}</a></p>
+ <p class="mb-1"><a href="/{{.List}}/message/{{.Id}}" class="text-muted">{{.GetSubject}}</a></p>
{{end}}
</div>
</div>
@@ -87,7 +87,7 @@
{{$listName:=.Name}}
{{range .Messages}}
<tr>
- <td><a href="/{{$listName}}/message/{{.Id}}">{{.Subject}}</a></td>
+ <td><a href="/{{$listName}}/message/{{.Id}}">{{.GetSubject}}</a></td>
<td>{{.GetAuthorName}}</td>
</tr>
{{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}}
<tr>
- <td><a href="../../message/{{.Id}}">{{.Subject}}</a></td>
+ <td><a href="../../message/{{.Id}}">{{.GetSubject}}</a></td>
<td>{{.GetAuthorName}}</td>
<td><span class="ag-date">{{.Date.Format "Mon, 2 Jan 2006 15:04:05"}}</span></td>
</tr>
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}}
<tr>
- <td><a href="../../message/{{.Id}}">{{.Subject}}</a></td>
+ <td><a href="../../message/{{.Id}}">{{.GetSubject}}</a></td>
<td>{{.GetAuthorName}}</td>
<td><span class="ag-date">{{.Date.Format "Mon, 2 Jan 2006 15:04:05"}}</span></td>
</tr>
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 @@
<tr>
<th>Subject:</th>
- <td><strong>{{.Message.Subject}}</strong></td>
+ <td><strong>{{.Message.GetSubject}}</strong></td>
</tr>
<tr>
<th>Date:</th>
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 .}}
<tr>
- <td><a href="/{{.GetListNameFromSubject}}/message/{{.Id}}/">{{.Subject}}</a></td>
+ <td><a href="/{{.GetListNameFromSubject}}/message/{{.Id}}/">{{.GetSubject}}</a></td>
</tr>
{{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}}
<tr>
- <td><a href="/{{.GetListNameFromSubject}}/message/{{.Id}}">{{.Subject}}</a></td>
+ <td><a href="/{{.GetListNameFromSubject}}/message/{{.Id}}">{{.GetSubject}}</a></td>
<td>{{.GetAuthorName}}</td>
<td><span class="ag-date">{{.Date.Format "Mon, 2 Jan 2006 15:04:05"}}</span></td>
</tr>