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 {
|
if msg.BodyStructure == nil {
|
||||||
return ""
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var best []int
|
var best *IMAPPartNode
|
||||||
isTextPlain := false
|
isTextPlain := false
|
||||||
msg.BodyStructure.Walk(func(path []int, part *imap.BodyStructure) bool {
|
msg.BodyStructure.Walk(func(path []int, part *imap.BodyStructure) bool {
|
||||||
if !strings.EqualFold(part.MIMEType, "text") {
|
if !strings.EqualFold(part.MIMEType, "text") {
|
||||||
|
@ -176,33 +186,16 @@ func (msg *IMAPMessage) TextPartName() string {
|
||||||
switch strings.ToLower(part.MIMESubType) {
|
switch strings.ToLower(part.MIMESubType) {
|
||||||
case "plain":
|
case "plain":
|
||||||
isTextPlain = true
|
isTextPlain = true
|
||||||
best = path
|
best = newIMAPPartNode(msg, path, part)
|
||||||
case "html":
|
case "html":
|
||||||
if !isTextPlain {
|
if !isTextPlain {
|
||||||
best = path
|
best = newIMAPPartNode(msg, path, part)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
if best == nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
l := make([]string, len(best))
|
return 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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *IMAPMessage) Attachments() []IMAPPartNode {
|
func (msg *IMAPMessage) Attachments() []IMAPPartNode {
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
{{range .Messages}}
|
{{range .Messages}}
|
||||||
<li>
|
<li>
|
||||||
<a href="/message/{{$.Mailbox.Name | pathescape}}/{{.Uid}}?part={{.TextPartName}}">
|
<a href="{{.TextPart.URL false}}">
|
||||||
{{if .Envelope.Subject}}
|
{{if .Envelope.Subject}}
|
||||||
{{.Envelope.Subject}}
|
{{.Envelope.Subject}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
<div class="message-list-subject message-list-item {{ if not (.HasFlag "\\Seen") }}message-list-unread{{ end }}">
|
<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}}
|
{{if .Envelope.Subject}}
|
||||||
{{.Envelope.Subject}}
|
{{.Envelope.Subject}}
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
@ -123,10 +123,10 @@
|
||||||
|
|
||||||
<span class="followups">
|
<span class="followups">
|
||||||
{{if .Message.HasFlag "\\Draft"}}
|
{{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}}
|
{{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}}/reply?part={{.Message.TextPart.PathString}}">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}}/forward?part={{.Message.TextPart.PathString}}">Forward</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a
|
<a
|
||||||
class="nav-link"
|
class="nav-link"
|
||||||
href="/message/{{$.Mailbox.Name | pathescape}}/{{.Uid}}?part={{.TextPartName}}"
|
href="{{.TextPart.URL false}}"
|
||||||
>
|
>
|
||||||
<span class="text-muted date">
|
<span class="text-muted date">
|
||||||
{{ .Envelope.Date | formatdate }}
|
{{ .Envelope.Date | formatdate }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue