Corso: Exchange: Mail: Backup Details to include recipients --JSON ONLY (#2689)

<!-- Insert PR description-->
#### Adds  Email recipients to the backup details for Exchange Mail. If the recipients are of length greater than one, the list of individuals is included and separated by a `,`

---

#### Does this PR need a docs update or release note?
- [x]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature


#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* closes  #2687<issue>

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x]  Unit test
This commit is contained in:
Danny 2023-03-06 18:32:38 -08:00 committed by GitHub
parent 3f3d47a54a
commit 030147ddcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 34 deletions

View File

@ -357,19 +357,28 @@ func (c Mail) Serialize(
// ---------------------------------------------------------------------------
func MailInfo(msg models.Messageable) *details.ExchangeInfo {
sender := ""
subject := ptr.Val(msg.GetSubject())
received := ptr.Val(msg.GetReceivedDateTime())
created := ptr.Val(msg.GetCreatedDateTime())
var (
sender = graph.UnwrapEmailAddress(msg.GetSender())
subject = ptr.Val(msg.GetSubject())
received = ptr.Val(msg.GetReceivedDateTime())
created = ptr.Val(msg.GetCreatedDateTime())
recipients = make([]string, 0)
)
if msg.GetSender() != nil &&
msg.GetSender().GetEmailAddress() != nil {
sender = ptr.Val(msg.GetSender().GetEmailAddress().GetAddress())
if msg.GetToRecipients() != nil {
ppl := msg.GetToRecipients()
for _, entry := range ppl {
temp := graph.UnwrapEmailAddress(entry)
if len(temp) > 0 {
recipients = append(recipients, temp)
}
}
}
return &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: sender,
Recipient: recipients,
Subject: subject,
Received: received,
Created: created,

View File

@ -36,6 +36,7 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
i := &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Recipient: []string{},
Created: initial,
Modified: initial,
}
@ -56,6 +57,7 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
msg.SetSender(sr)
i := &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Recipient: []string{},
Sender: sender,
Created: initial,
Modified: initial,
@ -75,6 +77,7 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
ItemType: details.ExchangeMail,
Subject: subject,
Created: initial,
Recipient: []string{},
Modified: initial,
}
return msg, i
@ -90,6 +93,7 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
msg.SetReceivedDateTime(&now)
i := &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Recipient: []string{},
Received: now,
Created: initial,
Modified: initial,
@ -101,22 +105,31 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
name: "All fields",
msgAndRP: func() (models.Messageable, *details.ExchangeInfo) {
sender := "foo@bar.com"
receiver := "foofoo@bar.com"
subject := "Hello world"
now := time.Now()
sr := models.NewRecipient()
sea := models.NewEmailAddress()
recv := models.NewRecipient()
req := models.NewEmailAddress()
recvs := make([]models.Recipientable, 0)
msg := models.NewMessage()
msg.SetCreatedDateTime(&initial)
msg.SetLastModifiedDateTime(&initial)
sea.SetAddress(&sender)
sr.SetEmailAddress(sea)
msg.SetSender(sr)
req.SetAddress(&receiver)
recv.SetEmailAddress(req)
msg.SetSubject(&subject)
msg.SetReceivedDateTime(&now)
recvs = append(recvs, recv, sr)
msg.SetToRecipients(recvs)
i := &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: sender,
Subject: subject,
Recipient: []string{receiver, sender},
Received: now,
Created: initial,
Modified: initial,

View File

@ -0,0 +1,18 @@
package graph
// Contains helper methods that are common across multiple
// Microsoft Graph Applications.
import (
"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/microsoftgraph/msgraph-sdk-go/models"
)
func UnwrapEmailAddress(contact models.Recipientable) string {
var empty string
if contact == nil || contact.GetEmailAddress() == nil {
return empty
}
return ptr.Val(contact.GetEmailAddress().GetAddress())
}

View File

@ -516,6 +516,7 @@ type ExchangeInfo struct {
ItemType ItemType `json:"itemType,omitempty"`
Sender string `json:"sender,omitempty"`
Subject string `json:"subject,omitempty"`
Recipient []string `json:"recipient,omitempty"`
ParentPath string `json:"parentPath,omitempty"`
Received time.Time `json:"received,omitempty"`
EventStart time.Time `json:"eventStart,omitempty"`

View File

@ -94,6 +94,7 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
ItemType: ExchangeMail,
Sender: "sender",
ParentPath: "Parent",
Recipient: []string{"receiver"},
Subject: "subject",
Received: now,
},