{"action":"created","issue":{"url":"https://api.github.com/repos/eXorus/php-mime-mail-parser/issues/34","labels_url":"https://api.github.com/repos/eXorus/php-mime-mail-parser/issues/34/labels{/name}","comments_url":"https://api.github.com/repos/eXorus/php-mime-mail-parser/issues/34/comments","events_url":"https://api.github.com/repos/eXorus/php-mime-mail-parser/issues/34/events","html_url":"https://github.com/eXorus/php-mime-mail-parser/issues/34","id":53996620,"number":34,"title":"php-mime-mail-parser truncating attachments","user":{"login":"squareproton","id":5478285,"avatar_url":"https://avatars.githubusercontent.com/u/5478285?v=3","gravatar_id":"","url":"https://api.github.com/users/squareproton","html_url":"https://github.com/squareproton","followers_url":"https://api.github.com/users/squareproton/followers","following_url":"https://api.github.com/users/squareproton/following{/other_user}","gists_url":"https://api.github.com/users/squareproton/gists{/gist_id}","starred_url":"https://api.github.com/users/squareproton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squareproton/subscriptions","organizations_url":"https://api.github.com/users/squareproton/orgs","repos_url":"https://api.github.com/users/squareproton/repos","events_url":"https://api.github.com/users/squareproton/events{/privacy}","received_events_url":"https://api.github.com/users/squareproton/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-11T16:39:46Z","updated_at":"2015-01-11T18:19:57Z","closed_at":"2015-01-11T18:19:57Z","body":"Whilst using php-mime-mail-parser to parse some emails and extract attachments. In two cases I've found php-mime-mail-parser truncating attachments. I've tested with Zend php email libs and it can extract the attachments correctly.\r\n\r\nUnfortunately I can't attach the raw email here for privacy reasons. Should you want to look into this what is best way to share a raw email with you privately?\r\n\r\nMy email is squareproton@gmail.com.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/eXorus/php-mime-mail-parser/issues/comments/69504553","html_url":"https://github.com/eXorus/php-mime-mail-parser/issues/34#issuecomment-69504553","issue_url":"https://api.github.com/repos/eXorus/php-mime-mail-parser/issues/34","id":69504553,"user":{"login":"squareproton","id":5478285,"avatar_url":"https://avatars.githubusercontent.com/u/5478285?v=3","gravatar_id":"","url":"https://api.github.com/users/squareproton","html_url":"https://github.com/squareproton","followers_url":"https://api.github.com/users/squareproton/followers","following_url":"https://api.github.com/users/squareproton/following{/other_user}","gists_url":"https://api.github.com/users/squareproton/gists{/gist_id}","starred_url":"https://api.github.com/users/squareproton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squareproton/subscriptions","organizations_url":"https://api.github.com/users/squareproton/orgs","repos_url":"https://api.github.com/users/squareproton/repos","events_url":"https://api.github.com/users/squareproton/events{/privacy}","received_events_url":"https://api.github.com/users/squareproton/received_events","type":"User","site_admin":false},"created_at":"2015-01-11T18:19:57Z","updated_at":"2015-01-11T18:19:57Z","body":"Ok. So I've figured out what's happening and put in the workaround but I can't make any sense of it.\r\n\r\nThe attachment parsing is fine. It looks like a php weirdness.\r\n\r\nThe code in src/Parser, getAttachmentStream() is the culprit.\r\n```\r\n#!php\r\n    $attachment = $this->decodeContentTransfer($this->getPartBodyFromText($part), $encodingType);\r\n    fwrite($temp_fp, $attachment, strlen($attachment));\r\n```\r\n\r\nThe attachment is being decoded correctly but the call to fwrite() doesn't write all the data to the stream. Initially I thought this might be something to do with http://stackoverflow.com/questions/9473474/php-fwrite-doesnt-finish-writing-string-data-to-file-why but it return the correct number of bytes. I've tested writing to the stream in small chunks, writing to a file created with `fopen(, 'w+')` instead of `tmpfile()` and various different methods of reading the stream all with out success.\r\n\r\nIn the end I've just changed the the function `getAttachmentStream()` to return the payload as a string and modified the access methods `src/Attachment.php` to handle this which has solved the problem. If I didn't think it was so unlikely I'd be claiming this as a php bug in fwrite. The attachment isn't large either at ~144KB. \r\n\r\nAt this point I don't feel this is a problem in php-mime-mail-parser. I'll leave this as a open issue in case you want to do further work on this but I also feel this could now be safely closed."}}