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:
parent
3f3d47a54a
commit
030147ddcb
@ -357,22 +357,31 @@ 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,
|
||||
Subject: subject,
|
||||
Received: received,
|
||||
Created: created,
|
||||
Modified: ptr.OrNow(msg.GetLastModifiedDateTime()),
|
||||
ItemType: details.ExchangeMail,
|
||||
Sender: sender,
|
||||
Recipient: recipients,
|
||||
Subject: subject,
|
||||
Received: received,
|
||||
Created: created,
|
||||
Modified: ptr.OrNow(msg.GetLastModifiedDateTime()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,9 +35,10 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
ItemType: details.ExchangeMail,
|
||||
Recipient: []string{},
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
@ -55,10 +56,11 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
msg.SetSender(sr)
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Sender: sender,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
ItemType: details.ExchangeMail,
|
||||
Recipient: []string{},
|
||||
Sender: sender,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
@ -72,10 +74,11 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
|
||||
msg.SetCreatedDateTime(&initial)
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Subject: subject,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
ItemType: details.ExchangeMail,
|
||||
Subject: subject,
|
||||
Created: initial,
|
||||
Recipient: []string{},
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
@ -89,10 +92,11 @@ func (suite *MailAPIUnitSuite) TestMailInfo() {
|
||||
msg.SetLastModifiedDateTime(&initial)
|
||||
msg.SetReceivedDateTime(&now)
|
||||
i := &details.ExchangeInfo{
|
||||
ItemType: details.ExchangeMail,
|
||||
Received: now,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
ItemType: details.ExchangeMail,
|
||||
Recipient: []string{},
|
||||
Received: now,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
@ -101,25 +105,34 @@ 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,
|
||||
Received: now,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
ItemType: details.ExchangeMail,
|
||||
Sender: sender,
|
||||
Subject: subject,
|
||||
Recipient: []string{receiver, sender},
|
||||
Received: now,
|
||||
Created: initial,
|
||||
Modified: initial,
|
||||
}
|
||||
return msg, i
|
||||
},
|
||||
|
||||
18
src/internal/connector/graph/shared.go
Normal file
18
src/internal/connector/graph/shared.go
Normal 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())
|
||||
}
|
||||
@ -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"`
|
||||
|
||||
@ -94,6 +94,7 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() {
|
||||
ItemType: ExchangeMail,
|
||||
Sender: "sender",
|
||||
ParentPath: "Parent",
|
||||
Recipient: []string{"receiver"},
|
||||
Subject: "subject",
|
||||
Received: now,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user