Skip to content

Commit

Permalink
fix(GODT-2311): Add missing header to downloaded message.
Browse files Browse the repository at this point in the history
Gluon's internal ID header was not being applied to messages which are
re-downloaded from the connector if they are not available in the local
cache.
  • Loading branch information
LBeernaertProton committed Jan 27, 2023
1 parent 4ce9fef commit bc2d818
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/ProtonMail/gluon/limits"
"github.com/ProtonMail/gluon/rfc822"
"strings"
"sync/atomic"

Expand Down Expand Up @@ -634,14 +635,19 @@ func (state *State) getLiteral(ctx context.Context, messageID ids.MessageIDPair)
return nil, fmt.Errorf("message failed to load from cache (%v), failed to download from connector: %w", firstErr, err)
}

if err := state.user.GetStore().Set(messageID.InternalID, connectorLiteral); err != nil {
literalWithHeader, err := rfc822.SetHeaderValue(connectorLiteral, ids.InternalIDKey, messageID.InternalID.String())
if err != nil {
return nil, fmt.Errorf("failed to set internal ID on downloaded message: %w", err)
}

if err := state.user.GetStore().Set(messageID.InternalID, literalWithHeader); err != nil {
logrus.Errorf("Failed to store download message from connector: %v", err)
return nil, fmt.Errorf("message failed to load from cache (%v), failed to store new downloaded message: %w", firstErr, err)
}

logrus.Debugf("Message %v downloaded and stored ", messageID.InternalID.ShortID())

literal = connectorLiteral
literal = literalWithHeader
} else {
literal = storeLiteral
}
Expand Down
2 changes: 1 addition & 1 deletion tests/cache_reset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestFetchWhenFileDeletedFromCache(t *testing.T) {
newFetchCommand(t, client).withItems(goimap.FetchRFC822).fetch("1").forSeqNum(1, func(validator *validatorBuilder) {
validator.ignoreFlags()
validator.wantSectionString(goimap.FetchRFC822, func(t testing.TB, literal string) {
messageFromSection := skipGLUONHeader(literal)
messageFromSection := skipGLUONHeaderOrPanic(literal)
require.Equal(t, fullMessage, messageFromSection)
})
}).checkAndRequireMessageCount(1)
Expand Down

0 comments on commit bc2d818

Please sign in to comment.