From 4c5ba0482275d8bc8b52b1f05f45f18227331ca2 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Mon, 30 Jan 2023 20:12:41 +0100 Subject: [PATCH] fix(GODT-1804): Preserve MIME parameters when uploading attachments --- internal/user/smtp.go | 3 ++- pkg/message/parser.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/user/smtp.go b/internal/user/smtp.go index c16d2d27..09080e54 100644 --- a/internal/user/smtp.go +++ b/internal/user/smtp.go @@ -23,6 +23,7 @@ import ( "encoding/base64" "fmt" "io" + "mime" "net/mail" "runtime" "strings" @@ -419,7 +420,7 @@ func createAttachments( attachment, err := client.UploadAttachment(ctx, addrKR, proton.CreateAttachmentReq{ Filename: att.Name, MessageID: draftID, - MIMEType: rfc822.MIMEType(att.MIMEType), + MIMEType: rfc822.MIMEType(mime.FormatMediaType(att.MIMEType, att.MIMEParams)), Disposition: att.Disposition, ContentID: att.ContentID, Body: att.Data, diff --git a/pkg/message/parser.go b/pkg/message/parser.go index e0aa9445..6d5ee23c 100644 --- a/pkg/message/parser.go +++ b/pkg/message/parser.go @@ -66,6 +66,7 @@ type Attachment struct { Name string ContentID string MIMEType string + MIMEParams map[string]string Disposition proton.Disposition Data []byte } @@ -523,6 +524,7 @@ func parseAttachment(h message.Header, body []byte) (Attachment, error) { return Attachment{}, err } att.MIMEType = mimeType + att.MIMEParams = mimeTypeParams // Prefer attachment name from filename param in content disposition. // If not available, try to get it from name param in content type.