Re: MIME files decoding

From: Date: Thu, 15 Jul 2004 18:32:13 +0000
Subject: Re: MIME files decoding
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13712@lists.php.net to get a copy of this message
On Thu, 15 Jul 2004 11:29:51 -0600, C.F. Scheidecker Antunes <nando@antunes.eti.br> wrote: > Hello all, > > In order to use pear mimedecode.php I have a few questions that were not > answered by the documentation. > > I have emails that have .zip, .pdf, .txt and .csv files. > > Some emails have more than one attachment. > > I would like to have a php script to fetch these emails and save only > those with .zip , .txt and .csv deleting everything else. > > Can anyone point me how to use mimedecode so that I can keep the > original filename of the attachment. How can I obtain the file name? > (The following is untested, but should work) //$mailObj is passed by ref as it could be big function getFiles(&$mailObj, $fileTypes = array('.zip', '.txt', '.csv')) { if($mailObj->ctype_primary == 'multipart') { //normally I'd do a foreach here, but the parts may be big (files) for($i = 0; $i < count($mailObj->parts); ++$i) { getFiles($mailObj->parts[$i], $fileTypes); } } else { if(in_array(substr($mailObj->d_parameters['filename'], -4), $fileTypes)) { $fd = fopen($mailObj->d_parameters['filename'], 'w'); fwrite($fd, $mailObj->body); } } } $mailSource = The full source text of the e-mail, including headers and body; getFiles(Mail_mimeDecode::decode(array('decode_body' => true, 'include_body' => true, 'decode_headers' => true, 'input' => $mailSource))); -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

« previous php.pear.general (#13712) next »