GODT-2177: Use correct attachment disposition when content ID is set

This commit is contained in:
James Houlahan
2023-01-24 16:09:01 +01:00
parent f1404cd3ee
commit 60b1c4d8f7
3 changed files with 25 additions and 12 deletions

View File

@ -66,7 +66,7 @@ type Attachment struct {
Name string
ContentID string
MIMEType string
Disposition string
Disposition proton.Disposition
Data []byte
}
@ -528,7 +528,7 @@ func parseAttachment(h message.Header, body []byte) (Attachment, error) {
// If not available, try to get it from name param in content type.
// Otherwise fallback to attachment.bin.
if disp, dispParams, err := h.ContentDisposition(); err == nil {
att.Disposition = disp
att.Disposition = proton.Disposition(disp)
if filename, ok := dispParams["filename"]; ok {
att.Name = filename

View File

@ -25,6 +25,7 @@ import (
"path/filepath"
"testing"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/proton-bridge/v3/pkg/message/parser"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -631,15 +632,17 @@ func TestParseIcsAttachment(t *testing.T) {
assert.Equal(t, m.Attachments[0].MIMEType, "text/calendar")
assert.Equal(t, m.Attachments[0].Name, "invite.ics")
assert.Equal(t, m.Attachments[0].ContentID, "")
assert.Equal(t, m.Attachments[0].Disposition, "attachment")
assert.Equal(t, m.Attachments[0].Disposition, proton.Disposition("attachment"))
assert.Equal(t, string(m.Attachments[0].Data), "This is an ics calendar invite")
}
func TestParsePanic(t *testing.T) {
var err error
require.NotPanics(t, func() {
_, err = Parse(&panicReader{})
})
require.Error(t, err)
}