GODT-2252: Recover from deleted cached messages

Update to latest Gluon version and implement the new
`Connector.GetMessageLiteral` function.
This commit is contained in:
Leander Beernaert
2023-01-17 13:38:06 +01:00
parent fe009ca235
commit 0e9428aaae
6 changed files with 45 additions and 4 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.18
require (
github.com/0xAX/notificator v0.0.0-20220220101646-ee9b8921e557
github.com/Masterminds/semver/v3 v3.1.1
github.com/ProtonMail/gluon v0.14.2-0.20230113145313-7dc070e73340
github.com/ProtonMail/gluon v0.14.2-0.20230117124414-549c1f016d6e
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a
github.com/ProtonMail/go-proton-api v0.2.4-0.20230112102613-6ad201cdb337
github.com/ProtonMail/go-rfc5322 v0.11.0

4
go.sum
View File

@ -28,8 +28,8 @@ github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf h1:yc9daCCYUefEs
github.com/ProtonMail/bcrypt v0.0.0-20211005172633-e235017c1baf/go.mod h1:o0ESU9p83twszAU8LBeJKFAAMX14tISa0yk4Oo5TOqo=
github.com/ProtonMail/docker-credential-helpers v1.1.0 h1:+kvUIpwWcbtP3WFv5sSvkFn/XLzSqPOB5AAthuk9xPk=
github.com/ProtonMail/docker-credential-helpers v1.1.0/go.mod h1:mK0aBveCxhnQ756AmaTfXMZDeULvheYVhF/MWMErN5g=
github.com/ProtonMail/gluon v0.14.2-0.20230113145313-7dc070e73340 h1:NrE0XbpppwSPRDbhK0LMoyIkE/+89Nj83MF9jg/f0X8=
github.com/ProtonMail/gluon v0.14.2-0.20230113145313-7dc070e73340/go.mod h1:z2AxLIiBCT1K+0OBHyaDI7AEaO5qI6/BEC2TE42vs4Q=
github.com/ProtonMail/gluon v0.14.2-0.20230117124414-549c1f016d6e h1:OAbPvjrynaGbxQdRPSprV2tK73AlNOM9vzFSnyG4iBk=
github.com/ProtonMail/gluon v0.14.2-0.20230117124414-549c1f016d6e/go.mod h1:z2AxLIiBCT1K+0OBHyaDI7AEaO5qI6/BEC2TE42vs4Q=
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a h1:D+aZah+k14Gn6kmL7eKxoo/4Dr/lK3ChBcwce2+SQP4=
github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a/go.mod h1:oTGdE7/DlWIr23G0IKW3OXK9wZ5Hw1GGiaJFccTvZi4=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=

View File

@ -321,6 +321,29 @@ func (conn *imapConnector) CreateMessage(
return conn.importMessage(ctx, literal, wantLabelIDs, wantFlags, unread)
}
func (conn *imapConnector) GetMessageLiteral(ctx context.Context, id imap.MessageID) ([]byte, error) {
msg, err := conn.client.GetFullMessage(ctx, string(id))
if err != nil {
return nil, err
}
return safe.RLockRetErr(func() ([]byte, error) {
var literal []byte
err := withAddrKR(conn.apiUser, conn.apiAddrs[msg.AddressID], conn.vault.KeyPass(), func(_, addrKR *crypto.KeyRing) error {
l, buildErr := message.BuildRFC822(addrKR, msg.Message, msg.AttData, defaultJobOpts())
if buildErr != nil {
return buildErr
}
literal = l
return nil
})
return literal, err
}, conn.apiUserLock, conn.apiAddrsLock)
}
// AddMessagesToMailbox labels the given messages with the given label ID.
func (conn *imapConnector) AddMessagesToMailbox(ctx context.Context, messageIDs []imap.MessageID, mailboxID imap.MailboxID) error {
defer conn.goPollAPIEvents(false)

View File

@ -137,6 +137,7 @@ func TestFeatures(testingT *testing.T) {
ctx.Step(`^the user sets the address mode of user "([^"]*)" to "([^"]*)"$`, s.theUserSetsTheAddressModeOfUserTo)
ctx.Step(`^the user changes the gluon path$`, s.theUserChangesTheGluonPath)
ctx.Step(`^the user deletes the gluon files$`, s.theUserDeletesTheGluonFiles)
ctx.Step(`^the user deletes the gluon cache$`, s.theUserDeletesTheGluonCache)
ctx.Step(`^the user reports a bug$`, s.theUserReportsABug)
ctx.Step(`^the user hides All Mail$`, s.theUserHidesAllMail)
ctx.Step(`^the user shows All Mail$`, s.theUserShowsAllMail)

View File

@ -103,6 +103,16 @@ func (s *scenario) theUserDeletesTheGluonFiles() error {
return nil
}
func (s *scenario) theUserDeletesTheGluonCache() error {
if path, err := s.t.locator.ProvideGluonCachePath(); err != nil {
return fmt.Errorf("failed to get gluon cache path: %w", err)
} else if err := os.RemoveAll(path); err != nil {
return fmt.Errorf("failed to remove gluon cache path: %w", err)
}
return nil
}
func (s *scenario) theUserHasDisabledAutomaticUpdates() error {
var started bool

View File

@ -16,4 +16,11 @@ Feature: IMAP Fetch
Given IMAP client "1" sees the following messages in "INBOX":
| from | to | subject | date |
| john.doe@mail.com | [user:user]@[domain] | foo | 13 Aug 82 00:00 +0000 |
Then IMAP client "1" sees header "X-Original-Date: Sun, 13 Jul 1969 00:00:00 +0000" in message with subject "foo" in "INBOX"
Then IMAP client "1" sees header "X-Original-Date: Sun, 13 Jul 1969 00:00:00 +0000" in message with subject "foo" in "INBOX"
Scenario: Fetch from deleted cache
When the user deletes the gluon cache
Then IMAP client "1" sees the following messages in "INBOX":
| from | to | subject | date |
| john.doe@mail.com | [user:user]@[domain] | foo | 13 Aug 82 00:00 +0000 |