Hi
am just including the core part of the attachment saving

<? 
                //connecting to our remote server for downloding mails using 
POP3        
                $mail   = new Zend_Mail_Storage_Pop3(array('host'=>
'mail.mailserver.com','user'=>'[email protected]','password'=>'pass123'));

                //This foreach loop is using to saperate each message as the 
number of
messages                
                $msg    = 0;            
                $tot_messages = count($mail);
                foreach ($mail as $message){
                        
                        $msg++;
                        echo "Reading ". $msg." of ". $tot_messages." 
Message<br>";
                        $foundPart = null;
                        //Code for finding the body of the message
                        foreach (new 
RecursiveIteratorIterator($mail->getMessage($msg)) as $part)
{
                                
                                try {
                                        
                                        if (strtok($part->contentType, ';') == 
'text/plain') {
                                                $foundPart = $part;//the body 
of the message is taken to $foundPart
                                                break;
                                        }
                                } catch (Zend_Mail_Exception $e) {
                                        // ignore
                                }
                                                        
                        }
                        
                        
                        //Code for checking if the message has attachment then 
write it to new
file            
                        $message = $mail->getMessage($msg);
                        /*echo '<pre>';
                        print_r($message);
                        echo '</pre>';
                        */
                        $attachement    ="N";  //SETTING attachement= N as 
DEFAULT
                        echo "FROM:".$message->getHeader('from');
                        if(is_null($foundPart))
                                $foundPart = $message->getContent();
                        if($message->isMultipart()){
                                $part    = $message->getPart(2);
                                $type    = $part->getHeaders ();
                                $type    = $type['content-disposition'];
                                
                                if($type !="inline"){
                                                                
                                        $content        = 
base64_decode($part->getContent());
                                        $cnt_typ        = explode(";" , 
$part->contentType);
                                        $name           = 
explode("=",$cnt_typ[1]);
                                        $filename       = $name[1];//It is the 
file name of the attachement in
browser 
                                        //This for avoiding " from the file 
name when sent from yahoomail
                                        $filename       = str_replace('"'," 
",$filename);
                                        $filename       = trim($filename);
                                        
                                        $attachement    = $filename;//It is for 
add 
                                }       
                        }
                                        
                                        
                   //Code for create a new file for the attachement 
                        if($attachement != "N") {
                                
                                //Code for write the file path to the variable 
myfile to create a new
file for attachement                            
                                $myfile = $_SERVER['DOCUMENT_ROOT'] 
."/mail_files/" . $filename;        
                                
                                //create a new file and write the attachement 
to the file
                                $fh = fopen($myfile,'w') or die("can't open 
file");
                                fwrite($fh,$content);
                                fclose($fh);
                        }
                        
                        
                        $mail->removeMessage($msg);     
                        echo "Message Added to database and removed<br>";       
        
          } //END OF FOR EACH



phpbrat wrote:
> 
> 
> i want to download attachment from a pop3/imap mail account using Zend
> framework ..
> Can you please help me with this ? the script flow..
> 
> 


-- 
View this message in context: 
http://www.nabble.com/How-to-store-attachment-files-into-a-location-in-server-tp20732847p21869816.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to