Skip to content

Commit

Permalink
fix: Use previously cached literal in fetch keywords
Browse files Browse the repository at this point in the history
When fetching messages with the keywords RFC822, RFC822Header and
RFC822Text we were retrieving the literal from the store again rather
than using the cached version as originally intended.
  • Loading branch information
LBeernaertProton committed Jan 16, 2023
1 parent 7dc070e commit 2a510f1
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions internal/state/mailbox_fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ func (m *Mailbox) Fetch(ctx context.Context, seq *proto.SequenceSet, attributes
setSeen = true
}

if attribute.Keyword == proto.FetchKeyword_FetchKWRFC822 ||
attribute.Keyword == proto.FetchKeyword_FetchKWRFC822Header ||
attribute.Keyword == proto.FetchKeyword_FetchKWRFC822Text {
needsLiteral = true
}

op := func(snapMessage snapMsgWithSeq, message *ent.Message, literal []byte) (response.Item, error) {
return m.fetchKeyword(snapMessage, message, attribute.Keyword)
return m.fetchKeyword(snapMessage, message, attribute.Keyword, literal)
}

operations = append(operations, op)
Expand Down Expand Up @@ -162,7 +168,7 @@ func (m *Mailbox) Fetch(ctx context.Context, seq *proto.SequenceSet, attributes
return nil
}

func (m *Mailbox) fetchKeyword(msg snapMsgWithSeq, message *ent.Message, keyword proto.FetchKeyword) (response.Item, error) {
func (m *Mailbox) fetchKeyword(msg snapMsgWithSeq, message *ent.Message, keyword proto.FetchKeyword, literal []byte) (response.Item, error) {
switch keyword {
case proto.FetchKeyword_FetchKWEnvelope:
return response.ItemEnvelope(message.Envelope), nil
Expand All @@ -174,16 +180,16 @@ func (m *Mailbox) fetchKeyword(msg snapMsgWithSeq, message *ent.Message, keyword
return response.ItemInternalDate(message.Date), nil

case proto.FetchKeyword_FetchKWRFC822:
return m.fetchRFC822(msg.ID.InternalID)
return m.fetchRFC822(literal)

case proto.FetchKeyword_FetchKWRFC822Header:
return m.fetchRFC822Header(msg.ID.InternalID)
return m.fetchRFC822Header(literal)

case proto.FetchKeyword_FetchKWRFC822Size:
return response.ItemRFC822Size(message.Size), nil

case proto.FetchKeyword_FetchKWRFC822Text:
return m.fetchRFC822Text(msg.ID.InternalID)
return m.fetchRFC822Text(literal)

case proto.FetchKeyword_FetchKWBody:
return response.ItemBody(message.Body), nil
Expand All @@ -199,32 +205,17 @@ func (m *Mailbox) fetchKeyword(msg snapMsgWithSeq, message *ent.Message, keyword
}
}

func (m *Mailbox) fetchRFC822(messageID imap.InternalMessageID) (response.Item, error) {
literal, err := m.state.getLiteral(messageID)
if err != nil {
return nil, err
}

func (m *Mailbox) fetchRFC822(literal []byte) (response.Item, error) {
return response.ItemRFC822Literal(literal), nil
}

func (m *Mailbox) fetchRFC822Header(messageID imap.InternalMessageID) (response.Item, error) {
literal, err := m.state.getLiteral(messageID)
if err != nil {
return nil, err
}

func (m *Mailbox) fetchRFC822Header(literal []byte) (response.Item, error) {
section := rfc822.Parse(literal)

return response.ItemRFC822Header(section.Header()), nil
}

func (m *Mailbox) fetchRFC822Text(messageID imap.InternalMessageID) (response.Item, error) {
literal, err := m.state.getLiteral(messageID)
if err != nil {
return nil, err
}

func (m *Mailbox) fetchRFC822Text(literal []byte) (response.Item, error) {
section := rfc822.Parse(literal)

return response.ItemRFC822Text(section.Body()), nil
Expand Down

0 comments on commit 2a510f1

Please sign in to comment.