Browse Source

Replace IMAPMessage.TextPartName with TextPart

master
Simon Ser 4 years ago
parent
commit
8589228c73
No known key found for this signature in database GPG Key ID: FDE7BE0E88F5E48
5 changed files with 22 additions and 29 deletions
  1. +16
    -23
      plugins/base/imap.go
  2. +1
    -1
      plugins/base/public/mailbox.html
  3. +1
    -1
      themes/alps/mailbox.html
  4. +3
    -3
      themes/alps/message.html
  5. +1
    -1
      themes/sourcehut/mailbox.html

+ 16
- 23
plugins/base/imap.go View File

@@ -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 {


+ 1
- 1
plugins/base/public/mailbox.html View File

@@ -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}}


+ 1
- 1
themes/alps/mailbox.html View File

@@ -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}}


+ 3
- 3
themes/alps/message.html View File

@@ -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>


+ 1
- 1
themes/sourcehut/mailbox.html View File

@@ -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 }}


Loading…
Cancel
Save