Reste à prévoir la pagination et la recherche
This commit is contained in:
9
imap.go
9
imap.go
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"mime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -69,12 +70,11 @@ func (mb *MailBox) Connect() error {
|
||||
log.Println("Error connnecting to", imapServer, ":", err)
|
||||
return err
|
||||
}
|
||||
log.Println("Connected")
|
||||
|
||||
err = mb.Client.Login(mb.User, mb.Password).Wait()
|
||||
if err != nil {
|
||||
log.Fatal("failed to login:", err)
|
||||
}
|
||||
log.Println("Logged in")
|
||||
return nil
|
||||
}
|
||||
func (mb *MailBox) ListFolders() ([]string, error) {
|
||||
@@ -122,6 +122,7 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
post.Author = messages[0].Envelope.To[0].Name
|
||||
|
||||
post.Date = messages[0].Envelope.Date.Format("2006/01/02 15:04")
|
||||
post.DateTime = messages[0].Envelope.Date
|
||||
|
||||
section := messages[0].FindBodySection(bodySection)
|
||||
|
||||
@@ -186,7 +187,6 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
post.HTML = template.HTML(buf.String())
|
||||
post.GenerateExcerpt()
|
||||
}
|
||||
|
||||
default:
|
||||
log.Println("Content-Type:", part.Header.Get("Content-Type"))
|
||||
|
||||
@@ -198,6 +198,9 @@ func (mb *MailBox) GetMessages() ([]Post, error) {
|
||||
}
|
||||
posts = append(posts, post)
|
||||
}
|
||||
sort.Slice(posts, func(i, j int) bool {
|
||||
return posts[i].DateTime.After(posts[j].DateTime)
|
||||
})
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user