From aa2f0049e1c153e7b62dac882ba6e34bf0dd24f3 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Fri, 9 Feb 2024 21:10:03 +0530 Subject: [PATCH] Do not fail export on email attachments without name (#23) * Do not fail on email attachments without name * Add changelog entry * Allow posts to also have unnamed attachments --- CHANGELOG.md | 1 + src/internal/converters/eml/eml.go | 10 ++++++++++ src/internal/converters/eml/eml_test.go | 12 ++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 207e95997..319ec4540 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Handle the case where an email or event cannot be retrieved from Exchange due to an `ErrorCorruptData` error. Corso will skip over the item but report it in the backup summary. - Emails attached within other emails are now correctly exported - Use correct timezone for event start and end times in Exchange exports (helps fix issues in relative recurrence patterns) +- Gracefully handle email and post attachments without name when exporting to eml ## [v0.19.0] (beta) - 2024-02-06 diff --git a/src/internal/converters/eml/eml.go b/src/internal/converters/eml/eml.go index da6047645..42986a041 100644 --- a/src/internal/converters/eml/eml.go +++ b/src/internal/converters/eml/eml.go @@ -171,6 +171,13 @@ func getFileAttachment(ctx context.Context, attachment models.Attachmentable) (* } name := ptr.Val(attachment.GetName()) + if len(name) == 0 { + // Graph as of now does not let us create any attachments + // without a name, but we have run into instances where we have + // see attachments without a name, possibly from old + // data. This is for those cases. + name = "Unnamed" + } contentID, err := attachment.GetBackingStore().Get("contentId") if err != nil { @@ -472,6 +479,9 @@ func FromJSONPostToEML( } name := ptr.Val(attachment.GetName()) + if len(name) == 0 { + name = "Unnamed" + } contentID, err := attachment.GetBackingStore().Get("contentId") if err != nil { diff --git a/src/internal/converters/eml/eml_test.go b/src/internal/converters/eml/eml_test.go index eb0e98096..40b76cedd 100644 --- a/src/internal/converters/eml/eml_test.go +++ b/src/internal/converters/eml/eml_test.go @@ -162,6 +162,18 @@ func (suite *EMLUnitSuite) TestConvert_edge_cases() { require.NoError(suite.T(), err, "setting attachment content") }, }, + { + name: "attachment without name", + transform: func(msg models.Messageable) { + attachments := msg.GetAttachments() + attachments[1].SetName(ptr.To("")) + + // This test has to be run on a non inline attachment + // as inline attachments use contentID instead of name + // even when there is a name. + assert.False(suite.T(), ptr.Val(attachments[1].GetIsInline())) + }, + }, } for _, test := range tests {