diff --git a/src/pkg/services/m365/api/mail.go b/src/pkg/services/m365/api/mail.go index 3480fdfcd..606de8c2e 100644 --- a/src/pkg/services/m365/api/mail.go +++ b/src/pkg/services/m365/api/mail.go @@ -322,6 +322,9 @@ func (c Mail) GetItem( // https://learn.microsoft.com/en-us/answers/questions/1227026/pagination-not-working-when-fetching-message-attac logger.CtxErr(ctx, err).Info("fetching all attachments by id") + // Clear expand params + attachConfig.QueryParameters.Expand = []string{} + // Getting size just to log in case of error attachConfig.QueryParameters.Select = idAnd("size") diff --git a/src/pkg/services/m365/api/mail_test.go b/src/pkg/services/m365/api/mail_test.go index 073991f58..d627383b6 100644 --- a/src/pkg/services/m365/api/mail_test.go +++ b/src/pkg/services/m365/api/mail_test.go @@ -370,6 +370,52 @@ func (suite *MailAPIIntgSuite) TestMail_attachmentListDownload() { } } +func (suite *MailAPIIntgSuite) TestMail_GetAttachments() { + tests := []struct { + name string + messageID string + expect assert.ErrorAssertionFunc + }{ + { + name: "Attachment for a given message ID", + messageID: "", // @vkamra insert message id here + expect: assert.NoError, + }, + } + + for _, test := range tests { + suite.Run(test.name, func() { + t := suite.T() + + ctx, flush := tester.NewContext(t) + defer flush() + + item, _, err := suite.its.ac.Mail().GetItem( + ctx, + "", // @vkamra insert user id here + test.messageID, + false, + fault.New(true)) + test.expect(t, err) + + it, ok := item.(models.Messageable) + require.True(t, ok, "convert to messageable") + + var size int64 + + if it.GetBody() != nil { + content := ptr.Val(it.GetBody().GetContent()) + size = int64(len(content)) + } + + attachments := it.GetAttachments() + for _, attachment := range attachments { + size += int64(*attachment.GetSize()) + } + }) + } +} + func (suite *MailAPIIntgSuite) TestMail_PostLargeAttachment() { t := suite.T()