diff --git a/src/internal/converters/eml/eml.go b/src/internal/converters/eml/eml.go index 26e0fcb0c..4cb03bce4 100644 --- a/src/internal/converters/eml/eml.go +++ b/src/internal/converters/eml/eml.go @@ -2,8 +2,12 @@ package eml // This package helps convert from the json response // received from Graph API to .eml format (rfc0822). -// Ref: https://www.ietf.org/rfc/rfc0822.txt -// Ref: https://datatracker.ietf.org/doc/html/rfc5322 + +// RFC +// Original: https://www.ietf.org/rfc/rfc0822.txt +// New: https://datatracker.ietf.org/doc/html/rfc5322 +// Extension for MIME: https://www.ietf.org/rfc/rfc1521.txt + // Data missing from backup: // SetReturnPath SetPriority SetListUnsubscribe SetDkim // AddAlternative SetDSN (and any other X-MS specific headers) @@ -17,6 +21,7 @@ import ( mail "github.com/xhit/go-simple-mail/v2" "github.com/alcionai/corso/src/internal/common/ptr" + "github.com/alcionai/corso/src/internal/common/str" "github.com/alcionai/corso/src/pkg/logger" "github.com/alcionai/corso/src/pkg/services/m365/api" ) @@ -152,8 +157,23 @@ func FromJSON(ctx context.Context, body []byte) (string, error) { return "", clues.WrapWC(ctx, err, "invalid content bytes") } + name := ptr.Val(attachment.GetName()) + + contentID, err := attachment.GetBackingStore().Get("contentId") + if err != nil { + return "", clues.WrapWC(ctx, err, "getting content id for attachment") + } + + if contentID != nil { + cids, _ := str.AnyToString(contentID) + if len(cids) > 0 { + name = cids + } + } + email.Attach(&mail.File{ - Name: ptr.Val(attachment.GetName()), + // cannot use filename as inline attachment will not get mapped properly + Name: name, MimeType: kind, Data: bts, Inline: ptr.Val(attachment.GetIsInline()),