From 243002c34586d334587bfdf967c1ad50b1f45e67 Mon Sep 17 00:00:00 2001 From: Jared Hancock Date: Tue, 18 Feb 2014 17:53:34 -0600 Subject: [PATCH] Careful transcoding attachments with a charset 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. --- include/class.mailparse.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/class.mailparse.php b/include/class.mailparse.php index d8cd3e2e..5e9c596b 100644 --- a/include/class.mailparse.php +++ b/include/class.mailparse.php @@ -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