Skip to content

Why can we not send base64 data as attachment without either uf8 encoding it, or breaking html body?! #142

Description

@smileBeda
let base64Encoded = signedData.base64EncodedString()

        let gpgAttachment = Attachment(
                data: Data(base64Encoded.utf8),
                mime: "application/octet-stream", // or "application/octet-stream"
                name: "\(title).pdf.gpg",
                inline: false,
                additionalHeaders: [
                        "Content-Transfer-Encoding": "base64"
                    ]
            )
        
        let mail = Mail(
            from: from,
            to: [toUser],
            subject: emailSubject,
            text: "Please use a HTML ready Mail Client to view the email.",
            attachments: [
                Attachment(
                    htmlContent: htmlContent,
                    additionalHeaders: ["Content-Type": "text/html; charset=utf-8"]
                ),
                gpgAttachment
            ]
        )

The above works:

  • HTML in email will not be broken
  • file will be attached

BUT:
since file is a SIGNED file (thus a .gpg file), the above code will BREAK the signature as we encode it to utf8 and that messes the signature up

Thus:

let gpgAttachment = Attachment(
                data: signedData,
                mime: "application/octet-stream", // or "application/octet-stream"
                name: "\(title).pdf.gpg",
                inline: false,
                additionalHeaders: [
                        "Content-Transfer-Encoding": "base64"
                    ]
            )

File will now validate correctly (PGP signature valid) but this will mess up the HTML part of the mail rendering it gibberish like v�-蕳《ia秈q歒���m��鹈 7⒏?走}�etc etc

There must be something I miss.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions