From 90bed4c14ecd01414d458b331e17b40d6a733100 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Tue, 19 Dec 2023 23:40:56 +0530 Subject: [PATCH] Fix inline images for eml exports (#4879) We have to use `contentId` instead of name for inline attachments as filenames can be duplicated. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [ ] :sunflower: Feature - [x] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * # #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/converters/eml/eml.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) 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()),