From 60307e39fda5b87ba2d1c06caf3c741765da233b Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Tue, 5 Dec 2023 14:17:25 +0530 Subject: [PATCH] Handle cases where we don't have attachment data (#4773) Some attachments have an "item" field instead of "contentBytes". There are items like contacts, emails or calendar events which will not be a normal format and will have to be converted to a text format. --- #### 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 - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [x] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Issue(s) * https://github.com/alcionai/corso/issues/4772 * Needed for https://github.com/alcionai/corso/pull/4756 #### Test Plan - [ ] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- src/internal/converters/eml/eml.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/internal/converters/eml/eml.go b/src/internal/converters/eml/eml.go index 6abdc8b7f..e6a022282 100644 --- a/src/internal/converters/eml/eml.go +++ b/src/internal/converters/eml/eml.go @@ -125,6 +125,20 @@ func FromJSON(ctx context.Context, body []byte) (string, error) { return "", clues.WrapWC(ctx, err, "failed to get attachment bytes") } + if bytes == nil { + // Some attachments have an "item" field instead of + // "contentBytes". There are items like contacts, emails + // or calendar events which will not be a normal format + // and will have to be converted to a text format. + // TODO(meain): Handle custom attachments + // https://github.com/alcionai/corso/issues/4772 + logger.Ctx(ctx). + With("attachment_id", ptr.Val(attachment.GetId())). + Info("unhandled attachment type") + + continue + } + bts, ok := bytes.([]byte) if !ok { return "", clues.WrapWC(ctx, err, "invalid content bytes") @@ -139,8 +153,8 @@ func FromJSON(ctx context.Context, body []byte) (string, error) { } } - if email.GetError() != nil { - return "", clues.WrapWC(ctx, email.Error, "converting to eml") + if err = email.GetError(); err != nil { + return "", clues.WrapWC(ctx, err, "converting to eml") } return email.GetMessage(), nil