mcfloyd Posted September 26, 2014 Share Posted September 26, 2014 Hello, I'm having a huge issue right now decoding a zip file from an attachment with a content-encoding of quoted-printable. I have tried a couple different methods (such as decoding the entire attachment or decoding it line by line), but none have produced a valid file when saved. What I don't understand is that I can download and open the file in Outlook fine, so there must be something wrong with the decoder. Here is a code snippet of my recent attempt: elseif ($transferEncoding == 'quoted-printable'){ $fileError = true; $attachmentParts = explode("\n", $currentPart->getContent()); $attachmentArray = array(); foreach ($attachmentParts as $line){ array_push($attachmentArray, quoted_printable_decode($line)); } $attachment = implode("", $attachmentArray); file_put_contents($unzipPath . '.zip', $attachment); } $unzipper = new Decompress(array( 'adapter' => 'Zip', 'options' => array( 'target' => $unzipPath, ) )); $unzipper->filter($unzipPath . '.zip'); unlink($unzipPath . '.zip'); I'm using Zend Framework 2 methods for unzipping the file when it's done, but there is a CRC error because the file is getting corrupted during the decode. This is how the file compares to the original (using Beyond Compare 3): So it is finding the hex for CLRF and removing it from the file. Any ideas on this would be greatly appreciated as I have been trying to solve this for about a month now. Thanks, -mcfloyd Quote Link to comment Share on other sites More sharing options...
requinix Posted September 26, 2014 Share Posted September 26, 2014 $attachmentParts = explode("\n", $currentPart->getContent()); will cause problems if the newline is a \r\n. Try $attachmentParts = preg_split('/\r\n?|\n/', $currentPart->getContent()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.