From 6a581535e4b580ae5442d1c4c87c54dc6993ab21 Mon Sep 17 00:00:00 2001 From: Bernhard Breytenbach Date: Mon, 25 Aug 2014 14:15:35 +0200 Subject: [PATCH 1/2] Code cleanup for Attatchment::saveAs() --- src/Fetch/Attachment.php | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Fetch/Attachment.php b/src/Fetch/Attachment.php index 3be2ffd..bd16363 100644 --- a/src/Fetch/Attachment.php +++ b/src/Fetch/Attachment.php @@ -194,28 +194,30 @@ class Attachment { $dirname = dirname($path); if (file_exists($path)) { - if (!is_writable($path)) + if (!is_writable($path)) { return false; + } } elseif (!is_dir($dirname) || !is_writable($dirname)) { return false; } - if (($filePointer = fopen($path, 'w')) == false) + if (($filePointer = fopen($path, 'w')) == false) { return false; + } switch ($this->encoding) { - case 3: - case 'base64': - $streamFilter = stream_filter_append($filePointer, 'convert.base64-decode', STREAM_FILTER_WRITE); - break; + case 3: + case 'base64': + $streamFilter = stream_filter_append($filePointer, 'convert.base64-decode', STREAM_FILTER_WRITE); + break; - case 4: - case 'quoted-printable': - $streamFilter = stream_filter_append($filePointer, 'convert.quoted-printable-decode', STREAM_FILTER_WRITE); - break; + case 4: + case 'quoted-printable': + $streamFilter = stream_filter_append($filePointer, 'convert.quoted-printable-decode', STREAM_FILTER_WRITE); + break; - default: - $streamFilter = null; + default: + $streamFilter = null; } $result = imap_savebody($this->imapStream, $filePointer, $this->messageId, $this->partId ?: 1, FT_UID); From 3e9400bfe0d5a3604d8ef052b5df2f8a39301e7f Mon Sep 17 00:00:00 2001 From: Bernhard Breytenbach Date: Mon, 25 Aug 2014 14:29:36 +0200 Subject: [PATCH 2/2] Fix Attachment encoding problem when saving to disk The case statement returned true for 0 == 'quoted-printable', and base64 decoded all 7bit encoded attachments. I have removed the string representations as an int is always returned by PHP's imap functions for encoding type. --- src/Fetch/Attachment.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Fetch/Attachment.php b/src/Fetch/Attachment.php index bd16363..3b7c4a7 100644 --- a/src/Fetch/Attachment.php +++ b/src/Fetch/Attachment.php @@ -206,13 +206,11 @@ class Attachment } switch ($this->encoding) { - case 3: - case 'base64': + case 3: //base64 $streamFilter = stream_filter_append($filePointer, 'convert.base64-decode', STREAM_FILTER_WRITE); break; - case 4: - case 'quoted-printable': + case 4: //quoted-printable $streamFilter = stream_filter_append($filePointer, 'convert.quoted-printable-decode', STREAM_FILTER_WRITE); break;