zz
This commit is contained in:
15
imap.go
15
imap.go
@@ -119,10 +119,12 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
|
||||
post.Id = messages[0].Envelope.MessageID
|
||||
post.Title = post.Title[5:] // remove first chars = blog+whitespace
|
||||
post.Author = messages[0].Envelope.From[0].Name
|
||||
post.Date = messages[0].Envelope.Date.String()
|
||||
post.Author = messages[0].Envelope.To[0].Name
|
||||
|
||||
post.Date = messages[0].Envelope.Date.Format("2006/01/02 15:04")
|
||||
|
||||
section := messages[0].FindBodySection(bodySection)
|
||||
|
||||
ioReader := bytes.NewReader(section)
|
||||
mailReader, err := mail.CreateReader(ioReader)
|
||||
if err != nil {
|
||||
@@ -155,7 +157,10 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
}
|
||||
switch mediaType {
|
||||
case "text/plain":
|
||||
post.Text = string(body)
|
||||
if len(post.HTML) == 0 {
|
||||
post.Text = string(body)
|
||||
post.GenerateExcerpt()
|
||||
}
|
||||
case "text/html":
|
||||
post.HTML = ""
|
||||
nodes, err := html.Parse(strings.NewReader(string(body)))
|
||||
@@ -171,13 +176,15 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
var buf bytes.Buffer
|
||||
err = nil
|
||||
for child := htmlNode.FirstChild; child != nil; child = child.NextSibling {
|
||||
if err = html.Render(&buf, child); err != nil {
|
||||
err = html.Render(&buf, child)
|
||||
if err != nil {
|
||||
post.HTML = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
post.HTML = template.HTML(buf.String())
|
||||
post.GenerateExcerpt()
|
||||
}
|
||||
|
||||
default:
|
||||
|
Reference in New Issue
Block a user