fix(GODT-1804): Preserve MIME parameters when uploading attachments

This commit is contained in:
James Houlahan
2023-01-30 20:12:41 +01:00
committed by Jakub
parent d7ff54d679
commit 4c5ba04822
2 changed files with 4 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io" "io"
"mime"
"net/mail" "net/mail"
"runtime" "runtime"
"strings" "strings"
@ -419,7 +420,7 @@ func createAttachments(
attachment, err := client.UploadAttachment(ctx, addrKR, proton.CreateAttachmentReq{ attachment, err := client.UploadAttachment(ctx, addrKR, proton.CreateAttachmentReq{
Filename: att.Name, Filename: att.Name,
MessageID: draftID, MessageID: draftID,
MIMEType: rfc822.MIMEType(att.MIMEType), MIMEType: rfc822.MIMEType(mime.FormatMediaType(att.MIMEType, att.MIMEParams)),
Disposition: att.Disposition, Disposition: att.Disposition,
ContentID: att.ContentID, ContentID: att.ContentID,
Body: att.Data, Body: att.Data,

View File

@ -66,6 +66,7 @@ type Attachment struct {
Name string Name string
ContentID string ContentID string
MIMEType string MIMEType string
MIMEParams map[string]string
Disposition proton.Disposition Disposition proton.Disposition
Data []byte Data []byte
} }
@ -523,6 +524,7 @@ func parseAttachment(h message.Header, body []byte) (Attachment, error) {
return Attachment{}, err return Attachment{}, err
} }
att.MIMEType = mimeType att.MIMEType = mimeType
att.MIMEParams = mimeTypeParams
// Prefer attachment name from filename param in content disposition. // Prefer attachment name from filename param in content disposition.
// If not available, try to get it from name param in content type. // If not available, try to get it from name param in content type.