Recommend this page to a friend! |
Receive Mail | > | All threads | > | Inline images | > | (Un) Subscribe thread alerts |
|
Oniel7 - 2011-02-15 15:19:28
What about inline images in HTML body?
Miharbi Hernandez - 2011-04-19 19:53:37 - In reply to message 1 from Oniel7
tenia ese mismo problema, esta fue mi solución:
function GetImgAttach($mid,$path, $imagesAllowed=array('jpg','jpeg','png','gif')) // extract images attached { if(!$this->marubox) return false; $struckture = imap_fetchstructure($this->marubox,$mid); $ar=""; if($struckture->parts) { foreach($struckture->parts as $key => $value) { $enc=$struckture->parts[$key]->encoding; if(in_array(strtolower($struckture->parts[$key]->subtype),$imagesAllowed) ) { $name=$struckture->parts[$key]->dparameters[0]->value!=''?$struckture->parts[$key]->dparameters[0]->value : $struckture->parts[$key]->parameters[0]->value; $message = imap_fetchbody($this->marubox,$mid,$key+1); if ($enc == 0) $message = imap_8bit($message); if ($enc == 1) $message = imap_8bit ($message); if ($enc == 2) $message = imap_binary ($message); if ($enc == 3) $message = imap_base64 ($message); if ($enc == 4) $message = quoted_printable_decode($message); if ($enc == 5) $message = $message; $args = explode('.',$name); echo $extension = strtolower(end($args)); if(!in_array($extension,$imagesAllowed)){// this is for the error when the file name has no extension $name=md5($name).'.'.strtolower($struckture->parts[$key]->subtype); } if(!is_dir ($path)){ $old = umask(0); mkdir($path,0777); umask($old); } $fp=fopen($path.$name,"w"); fwrite($fp,$message); fclose($fp); $ar=$ar.$name.","; } // Support for embedded attachments starts here if($struckture->parts[$key]->parts) { foreach($struckture->parts[$key]->parts as $keyb => $valueb) { $enc=$struckture->parts[$key]->parts[$keyb]->encoding; if(in_array(strtolower($struckture->parts[$key]->parts[$keyb]->subtype),$imagesAllowed)) { $name=$struckture->parts[$key]->parts[$keyb]->dparameters[0]->value; $partnro = ($key+1).".".($keyb+1); $message = imap_fetchbody($this->marubox,$mid,$partnro); if ($enc == 0) $message = imap_8bit($message); if ($enc == 1) $message = imap_8bit ($message); if ($enc == 2) $message = imap_binary ($message); if ($enc == 3) $message = imap_base64 ($message); if ($enc == 4) $message = quoted_printable_decode($message); if ($enc == 5) $message = $message; $args = explode('.',$name); $extension = strtolower(end($args)); if(!in_array($extension,$imagesAllowed)){ $name=md5($name).'.'.strtolower($struckture->parts[$key]->parts[$keyb]->subtype); } if(!is_dir ($path)){ $old = umask(0); mkdir($path,0777); umask($old); } $fp=fopen($path.$name,"w"); fwrite($fp,$message); fclose($fp); $ar=$ar.$name.","; } } } } } $ar=substr($ar,0,(strlen($ar)-1)); return $ar; } |
info at phpclasses dot org
.