PDF attachments are changing to unusable DAT files
email, pdf
Solution
From the comments:
There's a weird Unicode character being printed instead of a hyphen here in the filename: "... Waterproofing – Universal City, ...". It could be that somebody's mailserver is sensitive to non-ASCII characters and is encoding it to base64 as a result. Change it to a regular ASCII hyphen and it should be fine.
How I found it:
Firstly, here's the online base64 decoder I used: http://www.opinionatedgeek.com/dotnet/tools/base64decode/
Secondly, I started by concatenating all of the base64 strings from the header. It's split up into multiple segments: for the first header, there are 5 segments. The segments are the long parts between the question marks. Putting them all together, you get:
Y2lCQmJIQm9ZU0JKYm5OMWJHRjBhVzl1Pz0NCiA9P3V0Zi04P0I/SUNZ
Z1YyRjBaWEp3Y205dlptbHVaeUF0SUVGc2NHaGhJRWx1YzNWc1lYUnBi
MjRnSmlCWFlYUmw/PQ0KID0/dXRmLTg/Qj9jbkJ5YjI5bWFXNW5JT0tB
a3lCVmJtbDJaWEp6WVd3Z1EybDBlU3dnS0RJd01USXRNRFF0TVRNcD89
DQogPT91dGYtOD9CP0xuQmtaZz09Pz0=
Putting this into the decoder gives:
ciBBbHBoYSBJbnN1bGF0aW9u?=
=?utf-8?B?ICYgV2F0ZXJwcm9vZmluZyAtIEFscGhhIEluc3VsYXRpb24gJiBXYXRl?=
=?utf-8?B?cnByb29maW5nIOKAkyBVbml2ZXJzYWwgQ2l0eSwgKDIwMTItMDQtMTMp?=
=?utf-8?B?LnBkZg==?=
Another set of base64 segments. The first segment looks like it's cut off, so I assume that what went into the filename is actually part of it. So I prepend it with that and get:
Q29uc29saWRhdGVkIEludm9pY2VzIGZvciBBbHBoYSBJbnN1bGF0aW9u
ICYgV2F0ZXJwcm9vZmluZyAtIEFscGhhIEluc3VsYXRpb24gJiBXYXRl
cnByb29maW5nIOKAkyBVbml2ZXJzYWwgQ2l0eSwgKDIwMTItMDQtMTMp
LnBkZg==
Putting this into the decoder will make it spit out a .bin file because of the non-ASCII character. The bin file contains the full filename of the PDF.
Opening the bin file in a hex editor:
43 6F 6E 73 6F 6C 69 64 61 74 65 64 20 49 6E 76 Consolidated Inv
6F 69 63 65 73 20 66 6F 72 20 41 6C 70 68 61 20 oices for ****
49 6E 73 75 6C 61 74 69 6F 6E 20 26 20 57 61 74 ********** & ***
65 72 70 72 6F 6F 66 69 6E 67 20 2D 20 41 6C 70 ********** - ***
68 61 20 49 6E 73 75 6C 61 74 69 6F 6E 20 26 20 ** ********** &
57 61 74 65 72 70 72 6F 6F 66 69 6E 67 20 E2 80 ************* â€
93 20 55 6E 69 76 65 72 73 61 6C 20 43 69 74 79 “ ********* ****
2C 20 28 32 30 31 32 2D 30 34 2D 31 33 29 2E 70 , (2012-04-13).p
64 66 df
The em-dash sticks out like a sore thumb.
Problem
I have an system that is an in house solution attempting to email invoices to clients. This system works great except for one client gets .dat files instead of the nicely generated .pdf files that everyone else gets. I have researched the problem and many things point to issues with Outlook sending emails(not using outlook) and splitting the files because it is to large(it isn't, we can manualy send the email fine.) The files get renamed to something like "=_utf-8_B_Q29uc29saWRhdGVkIEludm9pY2VzIGZv.dat" instead of "1180426.pdf". After the headers on both files is just lines of characters that don't mean anything to me. the headers of the .dat files: file1 ``` =?utf-8?B?Y2lCQmJIQm9ZU0JKYm5OMWJHRjBhVzl1Pz0NCiA9P3V0Zi04P0I/SUNZ?=\ \ =?utf-8?B?Z1YyRjBaWEp3Y205dlptbHVaeUF0SUVGc2NHaGhJRWx1YzNWc1lYUnBi?=\ \ =?utf-8?B?MjRnSmlCWFlYUmw/PQ0KID0/dXRmLTg/Qj9jbkJ5YjI5bWFXNW5JT0tB?=\ \ =?utf-8?B?a3lCVmJtbDJaWEp6WVd3Z1EybDBlU3dnS0RJd01USXRNRFF0TVRNcD89?=\ \ =?utf-8?B?DQogPT91dGYtOD9CP0xuQmtaZz09Pz0=?=" Content-Transfer-Encoding: base64 Content-Disposition: attachment ``` file2 ``` =?utf-8?B?YUdFZ1NXNXpkV3hoZEdsdmJpQW1JRmRoPz0NCiA9P3V0Zi04P0I/ZEdW?=\ \ =?utf-8?B?eWNISnZiMlpwYm1jZ0xTQkJiSEJvWVNCSmJuTjFiR0YwYVc5dUlDWWdW?=\ \ =?utf-8?B?MkYwWlhKd2NtOXY/PQ0KID0/dXRmLTg/Qj9abWx1WnlEaWdKTWdWVzVw?=\ \ =?utf-8?B?ZG1WeWMyRnNJRU5wZEhrc0lDZ3lNREV5TFRBMExURXpLUzV3WkdZPT89?=\ \ =?utf-8?B??=" Content-Transfer-Encoding: base64 Content-Disposition: attachment ``` Does anyone have any idea on why this is happening?