From 014c8af560cb2405dce8494c5cc8a5e51def265b Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Wed, 13 Jan 2021 16:42:10 +0100 Subject: [PATCH] fix: panic when no multipart/alternative children --- internal/bridge/release_notes.go | 2 +- pkg/message/parser.go | 8 ++++++-- unreleased.md | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/bridge/release_notes.go b/internal/bridge/release_notes.go index 534057af..e3a9e2c6 100644 --- a/internal/bridge/release_notes.go +++ b/internal/bridge/release_notes.go @@ -1,4 +1,4 @@ -// Copyright (c) 2020 Proton Technologies AG +// Copyright (c) 2021 Proton Technologies AG // // This file is part of ProtonMail Bridge. // diff --git a/pkg/message/parser.go b/pkg/message/parser.go index f32687ad..a77128b9 100644 --- a/pkg/message/parser.go +++ b/pkg/message/parser.go @@ -329,8 +329,12 @@ func bestChoice(childParts []parser.Parts, preferredContentType string) parser.P } } - // Otherwise, choose the last one. - return childParts[len(childParts)-1] + // Otherwise, choose the last one, if it exists. + if len(childParts) > 0 { + return childParts[len(childParts)-1] + } + + return parser.Parts{} } func allPartsHaveContentType(parts parser.Parts, contentType string) bool { diff --git a/unreleased.md b/unreleased.md index 4bde40bf..cb13df47 100644 --- a/unreleased.md +++ b/unreleased.md @@ -9,3 +9,6 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) ### Removed ### Changed + +### Fixed +* GODT-979 Fix panic when trying to parse a multipart/alternative section that has no child sections.