Update our message flags when server updates them
This commit is contained in:
parent
d63653ecde
commit
05f00f0153
3 changed files with 35 additions and 5 deletions
|
@ -112,9 +112,7 @@ func merge(to *types.MessageInfo, from *types.MessageInfo) {
|
||||||
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
|
||||||
to.Flags = from.Flags
|
|
||||||
}
|
|
||||||
if from.Size != 0 {
|
if from.Size != 0 {
|
||||||
to.Size = from.Size
|
to.Size = from.Size
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,11 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart(
|
||||||
imapw.worker.Logger.Printf("Fetching message part")
|
imapw.worker.Logger.Printf("Fetching message part")
|
||||||
section := &imap.BodySectionName{}
|
section := &imap.BodySectionName{}
|
||||||
section.Path = msg.Part
|
section.Path = msg.Part
|
||||||
items := []imap.FetchItem{section.FetchItem()}
|
items := []imap.FetchItem{
|
||||||
|
imap.FetchFlags,
|
||||||
|
imap.FetchUid,
|
||||||
|
section.FetchItem(),
|
||||||
|
}
|
||||||
uids := imap.SeqSet{}
|
uids := imap.SeqSet{}
|
||||||
uids.AddNum(msg.Uid)
|
uids.AddNum(msg.Uid)
|
||||||
imapw.handleFetchMessages(msg, &uids, items, section)
|
imapw.handleFetchMessages(msg, &uids, items, section)
|
||||||
|
@ -51,7 +55,11 @@ func (imapw *IMAPWorker) handleFetchFullMessages(
|
||||||
|
|
||||||
imapw.worker.Logger.Printf("Fetching full messages")
|
imapw.worker.Logger.Printf("Fetching full messages")
|
||||||
section := &imap.BodySectionName{}
|
section := &imap.BodySectionName{}
|
||||||
items := []imap.FetchItem{section.FetchItem()}
|
items := []imap.FetchItem{
|
||||||
|
imap.FetchFlags,
|
||||||
|
imap.FetchUid,
|
||||||
|
section.FetchItem(),
|
||||||
|
}
|
||||||
imapw.handleFetchMessages(msg, &msg.Uids, items, section)
|
imapw.handleFetchMessages(msg, &msg.Uids, items, section)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +97,12 @@ func (imapw *IMAPWorker) handleFetchMessages(
|
||||||
Reader: reader,
|
Reader: reader,
|
||||||
Uid: _msg.Uid,
|
Uid: _msg.Uid,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
// Update flags (to mark message as read)
|
||||||
|
imapw.worker.PostMessage(&types.MessageInfo{
|
||||||
|
Message: types.RespondTo(msg),
|
||||||
|
Flags: _msg.Flags,
|
||||||
|
Uid: _msg.Uid,
|
||||||
|
}, nil)
|
||||||
case *types.FetchMessageBodyPart:
|
case *types.FetchMessageBodyPart:
|
||||||
reader := _msg.GetBody(section)
|
reader := _msg.GetBody(section)
|
||||||
imapw.worker.PostMessage(&types.MessageBodyPart{
|
imapw.worker.PostMessage(&types.MessageBodyPart{
|
||||||
|
@ -96,6 +110,12 @@ func (imapw *IMAPWorker) handleFetchMessages(
|
||||||
Reader: reader,
|
Reader: reader,
|
||||||
Uid: _msg.Uid,
|
Uid: _msg.Uid,
|
||||||
}, nil)
|
}, nil)
|
||||||
|
// Update flags (to mark message as read)
|
||||||
|
imapw.worker.PostMessage(&types.MessageInfo{
|
||||||
|
Message: types.RespondTo(msg),
|
||||||
|
Flags: _msg.Flags,
|
||||||
|
Uid: _msg.Uid,
|
||||||
|
}, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done <- nil
|
done <- nil
|
||||||
|
|
|
@ -171,6 +171,18 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) {
|
||||||
Recent: int(status.Recent),
|
Recent: int(status.Recent),
|
||||||
Unseen: int(status.Unseen),
|
Unseen: int(status.Unseen),
|
||||||
}, nil)
|
}, nil)
|
||||||
|
case *client.MessageUpdate:
|
||||||
|
msg := update.Message
|
||||||
|
if msg.Uid == 0 {
|
||||||
|
msg.Uid = w.seqMap[msg.SeqNum-1]
|
||||||
|
}
|
||||||
|
w.worker.PostMessage(&types.MessageInfo{
|
||||||
|
BodyStructure: msg.BodyStructure,
|
||||||
|
Envelope: msg.Envelope,
|
||||||
|
Flags: msg.Flags,
|
||||||
|
InternalDate: msg.InternalDate,
|
||||||
|
Uid: msg.Uid,
|
||||||
|
}, nil)
|
||||||
case *client.ExpungeUpdate:
|
case *client.ExpungeUpdate:
|
||||||
i := update.SeqNum - 1
|
i := update.SeqNum - 1
|
||||||
uid := w.seqMap[i]
|
uid := w.seqMap[i]
|
||||||
|
|
Loading…
Reference in a new issue