Item size- sum of attachment and email body (#3291)
<!-- PR description--> Size of emails will be - sum of - size of attachment and size of email body In case of contacts and events, since mostly everything is data we will check the size as - total serialised bytes #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🐛 Bugfix #### Issue(s) * #3152 #### Test Plan - [ ] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
211701f9b1
commit
6c2b78de07
@ -134,6 +134,10 @@ func (c Mail) GetItem(
|
|||||||
immutableIDs bool,
|
immutableIDs bool,
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
) (serialization.Parsable, *details.ExchangeInfo, error) {
|
) (serialization.Parsable, *details.ExchangeInfo, error) {
|
||||||
|
var (
|
||||||
|
size int64
|
||||||
|
mailBody models.ItemBodyable
|
||||||
|
)
|
||||||
// Will need adjusted if attachments start allowing paging.
|
// Will need adjusted if attachments start allowing paging.
|
||||||
headers := buildPreferHeaders(false, immutableIDs)
|
headers := buildPreferHeaders(false, immutableIDs)
|
||||||
itemOpts := &users.ItemMessagesMessageItemRequestBuilderGetRequestConfiguration{
|
itemOpts := &users.ItemMessagesMessageItemRequestBuilderGetRequestConfiguration{
|
||||||
@ -145,8 +149,16 @@ func (c Mail) GetItem(
|
|||||||
return nil, nil, graph.Stack(ctx, err)
|
return nil, nil, graph.Stack(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ptr.Val(mail.GetHasAttachments()) && !HasAttachments(mail.GetBody()) {
|
mailBody = mail.GetBody()
|
||||||
return mail, MailInfo(mail), nil
|
if mailBody != nil {
|
||||||
|
content := ptr.Val(mailBody.GetContent())
|
||||||
|
if len(content) > 0 {
|
||||||
|
size = int64(len(content))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !ptr.Val(mail.GetHasAttachments()) && !HasAttachments(mailBody) {
|
||||||
|
return mail, MailInfo(mail, size), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
options := &users.ItemMessagesItemAttachmentsRequestBuilderGetRequestConfiguration{
|
options := &users.ItemMessagesItemAttachmentsRequestBuilderGetRequestConfiguration{
|
||||||
@ -163,8 +175,14 @@ func (c Mail) GetItem(
|
|||||||
Attachments().
|
Attachments().
|
||||||
Get(ctx, options)
|
Get(ctx, options)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
for _, a := range attached.GetValue() {
|
||||||
|
attachSize := ptr.Val(a.GetSize())
|
||||||
|
size = +int64(attachSize)
|
||||||
|
}
|
||||||
|
|
||||||
mail.SetAttachments(attached.GetValue())
|
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
|
// A failure can be caused by having a lot of attachments as
|
||||||
@ -214,11 +232,13 @@ func (c Mail) GetItem(
|
|||||||
}
|
}
|
||||||
|
|
||||||
atts = append(atts, att)
|
atts = append(atts, att)
|
||||||
|
attachSize := ptr.Val(a.GetSize())
|
||||||
|
size = +int64(attachSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
mail.SetAttachments(atts)
|
mail.SetAttachments(atts)
|
||||||
|
|
||||||
return mail, MailInfo(mail), nil
|
return mail, MailInfo(mail, size), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnumerateContainers iterates through all of the users current
|
// EnumerateContainers iterates through all of the users current
|
||||||
@ -419,7 +439,7 @@ func (c Mail) Serialize(
|
|||||||
// Helpers
|
// Helpers
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
func MailInfo(msg models.Messageable) *details.ExchangeInfo {
|
func MailInfo(msg models.Messageable, size int64) *details.ExchangeInfo {
|
||||||
var (
|
var (
|
||||||
sender = UnwrapEmailAddress(msg.GetSender())
|
sender = UnwrapEmailAddress(msg.GetSender())
|
||||||
subject = ptr.Val(msg.GetSubject())
|
subject = ptr.Val(msg.GetSubject())
|
||||||
@ -444,6 +464,7 @@ func MailInfo(msg models.Messageable) *details.ExchangeInfo {
|
|||||||
Recipient: recipients,
|
Recipient: recipients,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
Received: received,
|
Received: received,
|
||||||
|
Size: size,
|
||||||
Created: created,
|
Created: created,
|
||||||
Modified: ptr.OrNow(msg.GetLastModifiedDateTime()),
|
Modified: ptr.OrNow(msg.GetLastModifiedDateTime()),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -152,7 +152,7 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
msg, expected := tt.msgAndRP()
|
msg, expected := tt.msgAndRP()
|
||||||
assert.Equal(suite.T(), expected, api.MailInfo(msg))
|
assert.Equal(suite.T(), expected, api.MailInfo(msg, 0))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,6 +213,7 @@ func (suite *MailAPIIntgSuite) TestHugeAttachmentListDownload() {
|
|||||||
name string
|
name string
|
||||||
setupf func()
|
setupf func()
|
||||||
attachmentCount int
|
attachmentCount int
|
||||||
|
size int64
|
||||||
expect assert.ErrorAssertionFunc
|
expect assert.ErrorAssertionFunc
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -242,6 +243,9 @@ func (suite *MailAPIIntgSuite) TestHugeAttachmentListDownload() {
|
|||||||
|
|
||||||
atts := models.NewAttachmentCollectionResponse()
|
atts := models.NewAttachmentCollectionResponse()
|
||||||
aitem := models.NewAttachment()
|
aitem := models.NewAttachment()
|
||||||
|
|
||||||
|
asize := int32(50)
|
||||||
|
aitem.SetSize(&asize)
|
||||||
atts.SetValue([]models.Attachmentable{aitem})
|
atts.SetValue([]models.Attachmentable{aitem})
|
||||||
|
|
||||||
gock.New("https://graph.microsoft.com").
|
gock.New("https://graph.microsoft.com").
|
||||||
@ -250,6 +254,7 @@ func (suite *MailAPIIntgSuite) TestHugeAttachmentListDownload() {
|
|||||||
JSON(getJSONObject(suite.T(), atts))
|
JSON(getJSONObject(suite.T(), atts))
|
||||||
},
|
},
|
||||||
attachmentCount: 1,
|
attachmentCount: 1,
|
||||||
|
size: 50,
|
||||||
expect: assert.NoError,
|
expect: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -289,6 +294,7 @@ func (suite *MailAPIIntgSuite) TestHugeAttachmentListDownload() {
|
|||||||
JSON(getJSONObject(suite.T(), aitem))
|
JSON(getJSONObject(suite.T(), aitem))
|
||||||
},
|
},
|
||||||
attachmentCount: 1,
|
attachmentCount: 1,
|
||||||
|
size: 200,
|
||||||
expect: assert.NoError,
|
expect: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -330,6 +336,7 @@ func (suite *MailAPIIntgSuite) TestHugeAttachmentListDownload() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachmentCount: 5,
|
attachmentCount: 5,
|
||||||
|
size: 200,
|
||||||
expect: assert.NoError,
|
expect: assert.NoError,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -348,8 +355,23 @@ func (suite *MailAPIIntgSuite) TestHugeAttachmentListDownload() {
|
|||||||
it, ok := item.(models.Messageable)
|
it, ok := item.(models.Messageable)
|
||||||
require.True(suite.T(), ok, "convert to messageable")
|
require.True(suite.T(), ok, "convert to messageable")
|
||||||
|
|
||||||
|
var size int64
|
||||||
|
mailBody := it.GetBody()
|
||||||
|
if mailBody != nil {
|
||||||
|
content := ptr.Val(mailBody.GetContent())
|
||||||
|
if len(content) > 0 {
|
||||||
|
size = int64(len(content))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
attachments := it.GetAttachments()
|
||||||
|
for _, attachment := range attachments {
|
||||||
|
size = +int64(*attachment.GetSize())
|
||||||
|
}
|
||||||
|
|
||||||
assert.Equal(suite.T(), *it.GetId(), mid)
|
assert.Equal(suite.T(), *it.GetId(), mid)
|
||||||
assert.Equal(suite.T(), tt.attachmentCount, len(it.GetAttachments()), "attachment count")
|
assert.Equal(suite.T(), tt.attachmentCount, len(attachments), "attachment count")
|
||||||
|
assert.Equal(suite.T(), tt.size, size, "mail size")
|
||||||
assert.True(suite.T(), gock.IsDone(), "made all requests")
|
assert.True(suite.T(), gock.IsDone(), "made all requests")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -260,7 +260,12 @@ func (col *Collection) streamItems(ctx context.Context, errs *fault.Bus) {
|
|||||||
return
|
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()
|
info.ParentPath = col.locationPath.String()
|
||||||
|
|
||||||
col.data <- &Stream{
|
col.data <- &Stream{
|
||||||
|
|||||||
@ -218,8 +218,7 @@ func RestoreMailMessage(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := api.MailInfo(clone)
|
info := api.MailInfo(clone, int64(len(bits)))
|
||||||
info.Size = int64(len(bits))
|
|
||||||
|
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user