Replace IMAPMessage.TextPartName with TextPart
This commit is contained in:
parent
ac7a3fb156
commit
8589228c73
5 changed files with 22 additions and 29 deletions
|
@ -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 {
|
||||
|
|
|
@ -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}}
|
||||
|
|
|
@ -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}}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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…
Reference in a new issue