| Peter Valicek - Senior Cluster Engineer 2004-05-28, 2:36 pm |
| Hello,
I'm using the PEAR;;Mail_Mime class to decode incoming Mails and extract
the attachments.
With normal Textfiles this works well, but if *.gz file are in and I try
to extract them is
only normal text what I receive.
Example Code:
function _getAttachments( $part ) {
// check where we find the filename
if ( $part->ctype_parameters['name'] ) {
$filename = $this->_tmpdir.'/'.$part->ctype_parameters['name'];
} else {
$filename = $this->_tmpdir.'/'.$part->d_parameters['filename'];
}
// open filehandle
$fh = fopen($filename, 'w+');
// if encoded so decode and write down to file
if ( $part->headers['content-transfer-encoding'] == 'base64' ) {
fwrite($fh, base64_decode($part->body),
strlen(base64_decode($part->body)));
} elseif ( $part->headers['content-transfer-encoding'] == 'utf8' ) {
fwrite($fh, utf8_decode($part->body),
strlen(utf8_decode($part->body)));
} else {
fwrite($fh, $part->body, strlen($part->body));
}
fclose($fh);
// assign back to files array
$this->_files[] = array('filename' => $filename, 'type' =>
'attachment');
}
An then I check the files and see:
# file explorer.832ca1fc.spnb56-2004.04.13.08.38.tar.gz
explorer.832ca1fc.spnb56-2004.04.13.08.38.tar.gz: ascii text
and not
explorer.832ca1fc.spnb56-2004.04.13.08.38.tar.gz: gzip compressed
data - deflate method , original file name
My params for Mail_mimeDecode class are:
$this->_params = array(
'include_bodies' => true,
'decode_bodies' => false,
'decode_headers' => true
);
What I'm doing wrong?
thanks in forward.
Cheers
-Peter
|