note 81983 added to function.imap-fetchbody
| From: | anonymouslazyperson at osu1 dot php dot net | Date: | Sat, 22 Mar 2008 16:51:07 +0000 |
| Subject: | note 81983 added to function.imap-fetchbody | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137322@lists.php.net to get a copy of this message | ||
Expanding on a comment below about using munpack to extract attachments, here's a lazy
person's function that extracts attachments from mail with $msg_number from $mailbox and writes
them to $dir. It returns an array of filenames or false if there are no attachments.
function writeAttachmentsToDisk($mailbox, $msg_number, $dir){
if (!file_exists($dir)){
mkdir($dir);
}
$filename = "tmp.eml";
$email_file = $dir."/".$filename;
// write the message body to disk
imap_savebody ($mailbox, $email_file, $msg_number);
$command = "munpack -C $dir -fq $email_file";
// invoke munpack which will
// write all the attachments to $dir
exec($command,$output);
// if($output[0]!='Did not find anything to unpack from $filename') {
$found_file = false;
foreach ($output as $attach) {
$pieces = explode(" ", $attach);
$part = $pieces[0];
if (file_exists($dir.$part)){
$found_file = true;
$files[] = $part;
}
}
if (!$found_file){
//echo ("\nMail.php : no files found - cleaning up. ");
// didn't find any output files - delete the directory and email file
unlink($email_file);
rmdir($dir);
return false;
}
else {
// found some files- just delete the email file
unlink($email_file);
return $files;
}
}
----
Server IP: 92.48.74.199
Probable Submitter: 81.157.219.12
----
Manual Page -- http://www.php.net/manual/en/function.imap-fetchbody.php
Edit -- https://master.php.net/note/edit/81983
Del: integrated -- https://master.php.net/note/delete/81983/integrated
Del: useless -- https://master.php.net/note/delete/81983/useless
Del: bad code -- https://master.php.net/note/delete/81983/bad+code
Del: spam -- https://master.php.net/note/delete/81983/spam
Del: non-english -- https://master.php.net/note/delete/81983/non-english
Del: in docs -- https://master.php.net/note/delete/81983/in+docs
Del: other reasons-- https://master.php.net/note/delete/81983
Reject -- https://master.php.net/note/reject/81983
Search -- https://master.php.net/manage/user-notes.php