Archived Forum Post

Index of archived forum posts

Question:

Corrupted PDF when content-type is wrong

Dec 17 '13 at 04:14

Here's the scenario (ChilkatDotNet2.dll, 9.3.1.0):

Received an email with a PDF attached, the standard mail client/web client extract the file correctly, while the Chilkat.Email object loaded with the same message contains an invalid file.

If I lookup at the original source, with .FetchMime(uidl), this is what it shows at the start of the attachment

[...]
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Some File.pdf"
Content-Type: text/html; name="Some File.pdf"

JVBERi0xLjQKJcjH0MRGCjQgMCBvYmoKPDwKL1R5cGUgL091dGxpbmVzCi9Db3VudCAwCj4+
[...]

After i use the MIME string to generate the full Email object, this is how it's altered:

[...]
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Some File.pdf"
Content-Type: text/html; charset="utf-8"; name="Some File.pdf"

5YCl5JmE44St45Cu4pSK7J+I7JOQ4KmG4oC04oCw5omv4Kmq47C84ryK56WU5pWw4ryg55WP5rG0
[...]

Now, "Content-Type: text/html" is an error from the sender client, which i have no control of, but the problem is that the chilkat object re-encodes the attachment

If i manually alter the string, injecting "application/pdf" in the right spot, and then pass that to .SetFromMimeText(TheMimeText), the message is okay, but of course this is not a feasible workaround

is there any other way to avoid this?