Skip to content

Commit

Permalink
Careful transcoding attachments with a charset
Browse files Browse the repository at this point in the history
If a non-text attachment specifies a charset in the content-type header,
don't transcode the content before saving it to the database. This can
corrupt attachments which have a header like the following:

Content-Type: application/pdf; charset=UTF-8

Since a PDF contains binary data, coercing it to UTF-8 encoding will drop
characters not valid in UTF-8 and will corrupt the attachment data.
  • Loading branch information
Jared Hancock committed Feb 19, 2014
1 parent 789bdbf commit 243002c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/class.mailparse.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ function getAttachments($part=null){
'type' => strtolower($part->ctype_primary.'/'.$part->ctype_secondary),
);

if ($part->ctype_parameters['charset'])
if ($part->ctype_parameters['charset']
&& 0 === strcasecmp($part->ctype_primary, 'text'))
$file['data'] = $this->mime_encode($part->body,
$part->ctype_parameters['charset']);
else
Expand Down

0 comments on commit 243002c

Please sign in to comment.