Kitura / Kitura/Swift-SMTP

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

Open
#142 2 comments 0 reactions 1 assignee Claimed by @adam-rocska View on GitHub
Dominant language
Swift
Stars
290
Forks
68
PR merge metrics
No merged PRs in 30d

Description

```
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.