aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-05-20 16:25:25 +0200
committerSimon Ser <contact@emersion.fr>2020-05-20 16:25:25 +0200
commit8589228c73a8abb5de890bfbd3fa8ab2807dfda0 (patch)
tree2332b85ca8e47aa1ff4766cf341dbfa306d48501
parentac7a3fb1562696af5dd57d20ddd74979fd7b5650 (diff)
downloadalps-8589228c73a8abb5de890bfbd3fa8ab2807dfda0.tar.gz
alps-8589228c73a8abb5de890bfbd3fa8ab2807dfda0.zip
Replace IMAPMessage.TextPartName with TextPart
-rwxr-xr-xplugins/base/imap.go39
-rw-r--r--plugins/base/public/mailbox.html2
-rw-r--r--themes/alps/mailbox.html2
-rw-r--r--themes/alps/message.html6
-rw-r--r--themes/sourcehut/mailbox.html2
5 files changed, 22 insertions, 29 deletions
diff --git a/plugins/base/imap.go b/plugins/base/imap.go
index 06e6e20..04ce8d7 100755
--- a/plugins/base/imap.go
+++ b/plugins/base/imap.go
@@ -158,12 +158,22 @@ func (msg *IMAPMessage) URL() *url.URL {
}
}
-func (msg *IMAPMessage) TextPartName() string {
+func newIMAPPartNode(msg *IMAPMessage, path []int, part *imap.BodyStructure) *IMAPPartNode {
+ filename, _ := part.Filename()
+ return &IMAPPartNode{
+ Path: path,
+ MIMEType: strings.ToLower(part.MIMEType + "/" + part.MIMESubType),
+ Filename: filename,
+ Message: msg,
+ }
+}
+
+func (msg *IMAPMessage) TextPart() *IMAPPartNode {
if msg.BodyStructure == nil {
- return ""
+ return nil
}
- var best []int
+ var best *IMAPPartNode
isTextPlain := false
msg.BodyStructure.Walk(func(path []int, part *imap.BodyStructure) bool {
if !strings.EqualFold(part.MIMEType, "text") {
@@ -176,33 +186,16 @@ func (msg *IMAPMessage) TextPartName() string {
switch strings.ToLower(part.MIMESubType) {
case "plain":
isTextPlain = true
- best = path
+ best = newIMAPPartNode(msg, path, part)
case "html":
if !isTextPlain {
- best = path
+ best = newIMAPPartNode(msg, path, part)
}
}
return true
})
- if best == nil {
- return ""
- }
- l := make([]string, len(best))
- for i, partNum := range best {
- l[i] = strconv.Itoa(partNum)
- }
- return strings.Join(l, ".")
-}
-
-func newIMAPPartNode(msg *IMAPMessage, path []int, part *imap.BodyStructure) *IMAPPartNode {
- filename, _ := part.Filename()
- return &IMAPPartNode{
- Path: path,
- MIMEType: strings.ToLower(part.MIMEType + "/" + part.MIMESubType),
- Filename: filename,
- Message: msg,
- }
+ return best
}
func (msg *IMAPMessage) Attachments() []IMAPPartNode {
diff --git a/plugins/base/public/mailbox.html b/plugins/base/public/mailbox.html
index 45729d1..ff2e3a9 100644
--- a/plugins/base/public/mailbox.html
+++ b/plugins/base/public/mailbox.html
@@ -27,7 +27,7 @@
<ul>
{{range .Messages}}
<li>
- <a href="/message/{{$.Mailbox.Name | pathescape}}/{{.Uid}}?part={{.TextPartName}}">
+ <a href="{{.TextPart.URL false}}">
{{if .Envelope.Subject}}
{{.Envelope.Subject}}
{{else}}
diff --git a/themes/alps/mailbox.html b/themes/alps/mailbox.html
index dfc79fe..8d9aa54 100644
--- a/themes/alps/mailbox.html
+++ b/themes/alps/mailbox.html
@@ -43,7 +43,7 @@
{{ end }}
</div>
<div class="message-list-subject message-list-item {{ if not (.HasFlag "\\Seen") }}message-list-unread{{ end }}">
- <a href="{{.URL}}?part={{.TextPartName}}">
+ <a href="{{.TextPart.URL false}}">
{{if .Envelope.Subject}}
{{.Envelope.Subject}}
{{else}}
diff --git a/themes/alps/message.html b/themes/alps/message.html
index a60af4e..6e88297 100644
--- a/themes/alps/message.html
+++ b/themes/alps/message.html
@@ -123,10 +123,10 @@
<span class="followups">
{{if .Message.HasFlag "\\Draft"}}
- <a class="action-group button-link" href="{{.Message.URL}}/edit?part={{.Message.TextPartName}}">Edit draft</a>
+ <a class="action-group button-link" href="{{.Message.URL}}/edit?part={{.Message.TextPart.PathString}}">Edit draft</a>
{{else}}
- <a class="action-group button-link" href="{{.Message.URL}}/reply?part={{.Message.TextPartName}}">Reply</a>
- <a class="action-group button-link" href="{{.Message.URL}}/forward?part={{.Message.TextPartName}}">Forward</a>
+ <a class="action-group button-link" href="{{.Message.URL}}/reply?part={{.Message.TextPart.PathString}}">Reply</a>
+ <a class="action-group button-link" href="{{.Message.URL}}/forward?part={{.Message.TextPart.PathString}}">Forward</a>
{{end}}
</span>
</div>
diff --git a/themes/sourcehut/mailbox.html b/themes/sourcehut/mailbox.html
index 58eb52b..1175cbe 100644
--- a/themes/sourcehut/mailbox.html
+++ b/themes/sourcehut/mailbox.html
@@ -53,7 +53,7 @@
<li class="nav-item">
<a
class="nav-link"
- href="/message/{{$.Mailbox.Name | pathescape}}/{{.Uid}}?part={{.TextPartName}}"
+ href="{{.TextPart.URL false}}"
>
<span class="text-muted date">
{{ .Envelope.Date | formatdate }}