From 341bfd4616549976bc8181a1e2a908dffd65368b Mon Sep 17 00:00:00 2001 From: neha-Gupta1 Date: Wed, 3 May 2023 17:39:58 +0530 Subject: [PATCH] use correct attachment size --- .github/workflows/accSelector.yaml | 46 ------------------- src/internal/connector/exchange/api/mail.go | 26 +++++++++-- .../connector/exchange/api/mail_test.go | 2 +- .../exchange/exchange_data_collection.go | 7 ++- .../connector/exchange/service_restore.go | 3 +- 5 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 .github/workflows/accSelector.yaml diff --git a/.github/workflows/accSelector.yaml b/.github/workflows/accSelector.yaml deleted file mode 100644 index 2340d2427..000000000 --- a/.github/workflows/accSelector.yaml +++ /dev/null @@ -1,46 +0,0 @@ -name: SetM365AppAcc - -on: - workflow_call: - outputs: - client_app_slot: - value: ${{ jobs.GetM365App.outputs.client_app_slot }} - client_id_env: - value: ${{ jobs.GetM365App.outputs.client_id_env }} - client_secret_env: - value: ${{ jobs.GetM365App.outputs.client_secret_env }} - -jobs: - GetM365App: - environment: Testing - runs-on: ubuntu-latest - outputs: - client_app_slot: ${{ steps.roundrobin.outputs.CLIENT_APP_SLOT }} - client_id_env: ${{ steps.roundrobin.outputs.CLIENT_ID_ENV }} - client_secret_env: ${{ steps.roundrobin.outputs.CLIENT_SECRET_ENV }} - steps: - - name: Figure out which client id to use - id: roundrobin - run: | - slot=$((GITHUB_RUN_NUMBER % 4)) - echo "CLIENT_APP_SLOT=$slot" >> $GITHUB_OUTPUT - - case $slot in - - 0) - echo "CLIENT_ID_ENV=CLIENT_ID" >> $GITHUB_OUTPUT - echo "CLIENT_SECRET_ENV=CLIENT_SECRET" >> $GITHUB_OUTPUT - ;; - 1) - echo "CLIENT_ID_ENV=CLIENT_ID_2" >> $GITHUB_OUTPUT - echo "CLIENT_SECRET_ENV=CLIENT_SECRET_2" >> $GITHUB_OUTPUT - ;; - 2) - echo "CLIENT_ID_ENV=CLIENT_ID_3" >> $GITHUB_OUTPUT - echo "CLIENT_SECRET_ENV=CLIENT_SECRET_3" >> $GITHUB_OUTPUT - ;; - 3) - echo "CLIENT_ID_ENV=CLIENT_ID_4" >> $GITHUB_OUTPUT - echo "CLIENT_SECRET_ENV=CLIENT_SECRET_4" >> $GITHUB_OUTPUT - ;; - esac \ No newline at end of file diff --git a/src/internal/connector/exchange/api/mail.go b/src/internal/connector/exchange/api/mail.go index b011921b5..09d4f3deb 100644 --- a/src/internal/connector/exchange/api/mail.go +++ b/src/internal/connector/exchange/api/mail.go @@ -134,6 +134,10 @@ func (c Mail) GetItem( immutableIDs bool, errs *fault.Bus, ) (serialization.Parsable, *details.ExchangeInfo, error) { + var ( + size int64 + attachSize int32 + ) // Will need adjusted if attachments start allowing paging. headers := buildPreferHeaders(false, immutableIDs) itemOpts := &users.ItemMessagesMessageItemRequestBuilderGetRequestConfiguration{ @@ -146,7 +150,12 @@ func (c Mail) GetItem( } if !ptr.Val(mail.GetHasAttachments()) && !HasAttachments(mail.GetBody()) { - return mail, MailInfo(mail), nil + return mail, MailInfo(mail, 0), nil + } + + bodySize := ptr.Val(mail.GetBody().GetContent()) + if bodySize != "" { + size = int64(len(bodySize)) } options := &users.ItemMessagesItemAttachmentsRequestBuilderGetRequestConfiguration{ @@ -163,8 +172,13 @@ func (c Mail) GetItem( Attachments(). Get(ctx, options) if err == nil { + for _, a := range attached.GetValue() { + attachSize = ptr.Val(a.GetSize()) + size = size + int64(attachSize) + } + mail.SetAttachments(attached.GetValue()) - return mail, MailInfo(mail), nil + return mail, MailInfo(mail, size), nil } // A failure can be caused by having a lot of attachments as @@ -214,11 +228,14 @@ func (c Mail) GetItem( } atts = append(atts, att) + + attachSize = ptr.Val(a.GetSize()) + size = size + int64(attachSize) } mail.SetAttachments(atts) - return mail, MailInfo(mail), nil + return mail, MailInfo(mail, size), nil } // EnumerateContainers iterates through all of the users current @@ -419,7 +436,7 @@ func (c Mail) Serialize( // Helpers // --------------------------------------------------------------------------- -func MailInfo(msg models.Messageable) *details.ExchangeInfo { +func MailInfo(msg models.Messageable, size int64) *details.ExchangeInfo { var ( sender = UnwrapEmailAddress(msg.GetSender()) subject = ptr.Val(msg.GetSubject()) @@ -444,6 +461,7 @@ func MailInfo(msg models.Messageable) *details.ExchangeInfo { Recipient: recipients, Subject: subject, Received: received, + Size: size, Created: created, Modified: ptr.OrNow(msg.GetLastModifiedDateTime()), } diff --git a/src/internal/connector/exchange/api/mail_test.go b/src/internal/connector/exchange/api/mail_test.go index 2ce0cd537..e8e347923 100644 --- a/src/internal/connector/exchange/api/mail_test.go +++ b/src/internal/connector/exchange/api/mail_test.go @@ -152,7 +152,7 @@ func (suite *MailAPIUnitSuite) TestMailInfo() { for _, tt := range tests { suite.Run(tt.name, func() { msg, expected := tt.msgAndRP() - assert.Equal(suite.T(), expected, api.MailInfo(msg)) + assert.Equal(suite.T(), expected, api.MailInfo(msg, 0)) }) } } diff --git a/src/internal/connector/exchange/exchange_data_collection.go b/src/internal/connector/exchange/exchange_data_collection.go index 4a2760be4..441056ed6 100644 --- a/src/internal/connector/exchange/exchange_data_collection.go +++ b/src/internal/connector/exchange/exchange_data_collection.go @@ -260,7 +260,12 @@ func (col *Collection) streamItems(ctx context.Context, errs *fault.Bus) { return } - info.Size = int64(len(data)) + // In case of mail the size of data is calc as- size of body content+size of attachment + // in all other case the size is - total item's serialized size + if info.Size <= 0 { + info.Size = int64(len(data)) + } + info.ParentPath = col.locationPath.String() col.data <- &Stream{ diff --git a/src/internal/connector/exchange/service_restore.go b/src/internal/connector/exchange/service_restore.go index 82a0f0fca..49fff1a23 100644 --- a/src/internal/connector/exchange/service_restore.go +++ b/src/internal/connector/exchange/service_restore.go @@ -218,8 +218,7 @@ func RestoreMailMessage( return nil, err } - info := api.MailInfo(clone) - info.Size = int64(len(bits)) + info := api.MailInfo(clone, int64(len(bits))) return info, nil }