From bc2d818d9d139249ce5c4a4471245eba912c5562 Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Fri, 27 Jan 2023 09:35:28 +0100 Subject: [PATCH] fix(GODT-2311): Add missing header to downloaded message. 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. --- internal/state/state.go | 10 ++++++++-- tests/cache_reset_test.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/state/state.go b/internal/state/state.go index a21054ec..da294be1 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "github.com/ProtonMail/gluon/limits" + "github.com/ProtonMail/gluon/rfc822" "strings" "sync/atomic" @@ -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 } diff --git a/tests/cache_reset_test.go b/tests/cache_reset_test.go index 68b7d3d1..8d9a824f 100644 --- a/tests/cache_reset_test.go +++ b/tests/cache_reset_test.go @@ -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)