Pull BodyStructure up from IMAP worker

This commit is contained in:
Drew DeVault 2019-03-31 11:10:10 -04:00
parent 5d0402aeea
commit 1f23868652
3 changed files with 40 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package lib package lib
import ( import (
"time"
"github.com/emersion/go-imap" "github.com/emersion/go-imap"
"github.com/mohamedattahri/mail" "github.com/mohamedattahri/mail"
@ -91,10 +93,22 @@ func (store *MessageStore) FetchBodies(uids []uint32,
func (store *MessageStore) merge( func (store *MessageStore) merge(
to *types.MessageInfo, from *types.MessageInfo) { to *types.MessageInfo, from *types.MessageInfo) {
// TODO: Merge more shit if from.BodyStructure != nil {
to.BodyStructure = from.BodyStructure
}
if from.Envelope != nil { if from.Envelope != nil {
to.Envelope = from.Envelope to.Envelope = from.Envelope
} }
if len(from.Flags) != 0 {
to.Flags = from.Flags
}
if from.Size != 0 {
to.Size = from.Size
}
var zero time.Time
if from.InternalDate != zero {
to.InternalDate = from.InternalDate
}
} }
func (store *MessageStore) Update(msg types.WorkerMessage) { func (store *MessageStore) Update(msg types.WorkerMessage) {

View File

@ -12,6 +12,7 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders(
imapw.worker.Logger.Printf("Fetching message headers") imapw.worker.Logger.Printf("Fetching message headers")
items := []imap.FetchItem{ items := []imap.FetchItem{
imap.FetchBodyStructure,
imap.FetchEnvelope, imap.FetchEnvelope,
imap.FetchInternalDate, imap.FetchInternalDate,
imap.FetchFlags, imap.FetchFlags,
@ -57,6 +58,7 @@ func (imapw *IMAPWorker) handleFetchMessages(
}, nil) }, nil)
} else { } else {
imapw.worker.PostMessage(&types.MessageInfo{ imapw.worker.PostMessage(&types.MessageInfo{
BodyStructure: _msg.BodyStructure,
Envelope: _msg.Envelope, Envelope: _msg.Envelope,
Flags: _msg.Flags, Flags: _msg.Flags,
InternalDate: _msg.InternalDate, InternalDate: _msg.InternalDate,

View File

@ -2,6 +2,7 @@ package types
import ( import (
"crypto/x509" "crypto/x509"
"io"
"time" "time"
"github.com/emersion/go-imap" "github.com/emersion/go-imap"
@ -86,6 +87,12 @@ type FetchMessageBodies struct {
Uids imap.SeqSet Uids imap.SeqSet
} }
type FetchMessageBodyPart struct {
Message
Uid uint32
Part int
}
type DeleteMessages struct { type DeleteMessages struct {
Message Message
Uids imap.SeqSet Uids imap.SeqSet
@ -120,6 +127,7 @@ type DirectoryContents struct {
type MessageInfo struct { type MessageInfo struct {
Message Message
BodyStructure *imap.BodyStructure
Envelope *imap.Envelope Envelope *imap.Envelope
Flags []string Flags []string
InternalDate time.Time InternalDate time.Time
@ -133,6 +141,12 @@ type MessageBody struct {
Uid uint32 Uid uint32
} }
type MessageBodyPart struct {
Message
Reader *io.Reader
Uid uint32
}
type MessagesDeleted struct { type MessagesDeleted struct {
Message Message
Uids []uint32 Uids []uint32