Export IMAPMessage

This is a public type other plugins and templates may want to access.
This commit is contained in:
Simon Ser 2019-12-16 15:46:29 +01:00
parent 08b259bd50
commit 4449416357
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 16 additions and 16 deletions

View file

@ -21,7 +21,7 @@ type MailboxRenderData struct {
koushin.RenderData koushin.RenderData
Mailbox *imap.MailboxStatus Mailbox *imap.MailboxStatus
Mailboxes []*imap.MailboxInfo Mailboxes []*imap.MailboxInfo
Messages []imapMessage Messages []IMAPMessage
PrevPage, NextPage int PrevPage, NextPage int
Query string Query string
} }
@ -45,7 +45,7 @@ func handleGetMailbox(ectx echo.Context) error {
query := ctx.FormValue("query") query := ctx.FormValue("query")
var mailboxes []*imap.MailboxInfo var mailboxes []*imap.MailboxInfo
var msgs []imapMessage var msgs []IMAPMessage
var mbox *imap.MailboxStatus var mbox *imap.MailboxStatus
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
var err error var err error
@ -121,7 +121,7 @@ func handleLogout(ectx echo.Context) error {
type MessageRenderData struct { type MessageRenderData struct {
koushin.RenderData koushin.RenderData
Mailbox *imap.MailboxStatus Mailbox *imap.MailboxStatus
Message *imapMessage Message *IMAPMessage
Body string Body string
PartPath string PartPath string
MailboxPage int MailboxPage int
@ -138,7 +138,7 @@ func handleGetPart(ctx *koushin.Context, raw bool) error {
return echo.NewHTTPError(http.StatusBadRequest, err) return echo.NewHTTPError(http.StatusBadRequest, err)
} }
var msg *imapMessage var msg *IMAPMessage
var part *message.Entity var part *message.Entity
var mbox *imap.MailboxStatus var mbox *imap.MailboxStatus
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
@ -219,7 +219,7 @@ func handleCompose(ectx echo.Context) error {
return echo.NewHTTPError(http.StatusBadRequest, err) return echo.NewHTTPError(http.StatusBadRequest, err)
} }
var inReplyTo *imapMessage var inReplyTo *IMAPMessage
var part *message.Entity var part *message.Entity
err = ctx.Session.DoIMAP(func(c *imapclient.Client) error { err = ctx.Session.DoIMAP(func(c *imapclient.Client) error {
var err error var err error

View file

@ -45,7 +45,7 @@ func ensureMailboxSelected(conn *imapclient.Client, mboxName string) error {
return nil return nil
} }
type imapMessage struct { type IMAPMessage struct {
*imap.Message *imap.Message
} }
@ -94,7 +94,7 @@ func textPartPath(bs *imap.BodyStructure) ([]int, bool) {
return nil, false return nil, false
} }
func (msg *imapMessage) TextPartName() string { func (msg *IMAPMessage) TextPartName() string {
if msg.BodyStructure == nil { if msg.BodyStructure == nil {
return "" return ""
} }
@ -166,7 +166,7 @@ func imapPartTree(bs *imap.BodyStructure, path []int) *IMAPPartNode {
return node return node
} }
func (msg *imapMessage) PartTree() *IMAPPartNode { func (msg *IMAPMessage) PartTree() *IMAPPartNode {
if msg.BodyStructure == nil { if msg.BodyStructure == nil {
return nil return nil
} }
@ -174,7 +174,7 @@ func (msg *imapMessage) PartTree() *IMAPPartNode {
return imapPartTree(msg.BodyStructure, nil) return imapPartTree(msg.BodyStructure, nil)
} }
func listMessages(conn *imapclient.Client, mboxName string, page int) ([]imapMessage, error) { func listMessages(conn *imapclient.Client, mboxName string, page int) ([]IMAPMessage, error) {
if err := ensureMailboxSelected(conn, mboxName); err != nil { if err := ensureMailboxSelected(conn, mboxName); err != nil {
return nil, err return nil, err
} }
@ -200,9 +200,9 @@ func listMessages(conn *imapclient.Client, mboxName string, page int) ([]imapMes
done <- conn.Fetch(&seqSet, fetch, ch) done <- conn.Fetch(&seqSet, fetch, ch)
}() }()
msgs := make([]imapMessage, 0, to-from) msgs := make([]IMAPMessage, 0, to-from)
for msg := range ch { for msg := range ch {
msgs = append(msgs, imapMessage{msg}) msgs = append(msgs, IMAPMessage{msg})
} }
if err := <-done; err != nil { if err := <-done; err != nil {
@ -218,7 +218,7 @@ func listMessages(conn *imapclient.Client, mboxName string, page int) ([]imapMes
return msgs, nil return msgs, nil
} }
func searchMessages(conn *imapclient.Client, mboxName, query string) ([]imapMessage, error) { func searchMessages(conn *imapclient.Client, mboxName, query string) ([]IMAPMessage, error) {
if err := ensureMailboxSelected(conn, mboxName); err != nil { if err := ensureMailboxSelected(conn, mboxName); err != nil {
return nil, err return nil, err
} }
@ -249,13 +249,13 @@ func searchMessages(conn *imapclient.Client, mboxName, query string) ([]imapMess
done <- conn.Fetch(&seqSet, fetch, ch) done <- conn.Fetch(&seqSet, fetch, ch)
}() }()
msgs := make([]imapMessage, len(nums)) msgs := make([]IMAPMessage, len(nums))
for msg := range ch { for msg := range ch {
i, ok := indexes[msg.SeqNum] i, ok := indexes[msg.SeqNum]
if !ok { if !ok {
continue continue
} }
msgs[i] = imapMessage{msg} msgs[i] = IMAPMessage{msg}
} }
if err := <-done; err != nil { if err := <-done; err != nil {
@ -265,7 +265,7 @@ func searchMessages(conn *imapclient.Client, mboxName, query string) ([]imapMess
return msgs, nil return msgs, nil
} }
func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPath []int) (*imapMessage, *message.Entity, error) { func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPath []int) (*IMAPMessage, *message.Entity, error) {
if err := ensureMailboxSelected(conn, mboxName); err != nil { if err := ensureMailboxSelected(conn, mboxName); err != nil {
return nil, nil, err return nil, nil, err
} }
@ -320,5 +320,5 @@ func getMessagePart(conn *imapclient.Client, mboxName string, uid uint32, partPa
return nil, nil, fmt.Errorf("failed to create message reader: %v", err) return nil, nil, fmt.Errorf("failed to create message reader: %v", err)
} }
return &imapMessage{msg}, part, nil return &IMAPMessage{msg}, part, nil
} }