From 891814f15c87dab6975604cfb444a6113ece7d34 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Mon, 18 Dec 2023 14:12:40 +0530 Subject: [PATCH] Add shortref and rename item_id (#4868) --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * # #### Test Plan - [ ] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/converters/eml/eml.go | 2 +- src/internal/m365/collection/exchange/export.go | 6 ++++-- src/internal/m365/service/exchange/export_test.go | 7 +++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/internal/converters/eml/eml.go b/src/internal/converters/eml/eml.go index e6a022282..3f1421a13 100644 --- a/src/internal/converters/eml/eml.go +++ b/src/internal/converters/eml/eml.go @@ -44,7 +44,7 @@ func FromJSON(ctx context.Context, body []byte) (string, error) { return "", clues.Wrap(err, "converting to messageble") } - ctx = clues.Add(ctx, "id", ptr.Val(data.GetId())) + ctx = clues.Add(ctx, "item_id", ptr.Val(data.GetId())) email := mail.NewMSG() email.AllowDuplicateAddress = true // More "correct" conversion diff --git a/src/internal/m365/collection/exchange/export.go b/src/internal/m365/collection/exchange/export.go index c3e761a2c..59f24a527 100644 --- a/src/internal/m365/collection/exchange/export.go +++ b/src/internal/m365/collection/exchange/export.go @@ -44,7 +44,9 @@ func streamItems( errs := fault.New(false) for _, rc := range drc { - for item := range rc.Items(ctx, errs) { + ictx := clues.Add(ctx, "path_short_ref", rc.FullPath().ShortRef()) + + for item := range rc.Items(ictx, errs) { id := item.ID() name := id + ".eml" @@ -64,7 +66,7 @@ func streamItems( continue } - email, err := eml.FromJSON(ctx, content) + email, err := eml.FromJSON(ictx, content) if err != nil { ch <- export.Item{ ID: id, diff --git a/src/internal/m365/service/exchange/export_test.go b/src/internal/m365/service/exchange/export_test.go index cfae24096..995b231db 100644 --- a/src/internal/m365/service/exchange/export_test.go +++ b/src/internal/m365/service/exchange/export_test.go @@ -33,6 +33,10 @@ func TestExportUnitSuite(t *testing.T) { func (suite *ExportUnitSuite) TestGetItems() { emailBodyBytes := []byte(testdata.EmailWithAttachments) + pb := path.Builder{}.Append("Inbox") + p, err := pb.ToDataLayerPath("t", "r", path.ExchangeService, path.EmailCategory, false) + assert.NoError(suite.T(), err, "build path") + table := []struct { name string version int @@ -44,6 +48,7 @@ func (suite *ExportUnitSuite) TestGetItems() { version: 1, backingCollection: data.NoFetchRestoreCollection{ Collection: dataMock.Collection{ + Path: p, ItemData: []data.Item{ &dataMock.Item{ ItemID: "id1", @@ -65,6 +70,7 @@ func (suite *ExportUnitSuite) TestGetItems() { version: 1, backingCollection: data.NoFetchRestoreCollection{ Collection: dataMock.Collection{ + Path: p, ItemData: []data.Item{ &dataMock.Item{ ItemID: "id1", @@ -95,6 +101,7 @@ func (suite *ExportUnitSuite) TestGetItems() { version: version.Groups9Update, backingCollection: data.FetchRestoreCollection{ Collection: dataMock.Collection{ + Path: p, ItemData: []data.Item{ &dataMock.Item{ ItemID: "id0",