Function to extract email attachments using PHP IMAP
Posted on
16th Feb 2014 07:03 pm by
admin
function extract_attachments($connection, $message_number) {
$attachments = array();
$structure = imap_fetchstructure($connection, $message_number);
if(isset($structure->parts) && count($structure->parts)) {
for($i = 0; $i < count($structure->parts); $i++) {
$attachments[$i] = array(
'is_attachment' => false,
'filename' => '',
'name' => '',
'attachment' => ''
);
if($structure->parts[$i]->ifdparameters) {
foreach($structure->parts[$i]->dparameters as $object) {
if(strtolower($object->attribute) == 'filename') {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['filename'] = $object->value;
}
}
}
if($structure->parts[$i]->ifparameters) {
foreach($structure->parts[$i]->parameters as $object) {
if(strtolower($object->attribute) == 'name') {
$attachments[$i]['is_attachment'] = true;
$attachments[$i]['name'] = $object->value;
}
}
}
if($attachments[$i]['is_attachment']) {
$attachments[$i]['attachment'] = imap_fetchbody($connection, $message_number, $i+1);
if($structure->parts[$i]->encoding == 3) { // 3 = BASE64
$attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']);
}
elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE
$attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']);
}
}
}
}
return $attachments;
}
can anyone please explain this code
No comments posted yet
Your Answer:
Login to answer
147 16
Other forums
grouping within a foreach?
hello all,
I currently have a list of products spit out from my db via a foreach loop. Right
EU VAT Package 2010
Does any one know whether SAP will be developing new reporting functionality due the new VAT rules t
SQL Injection
In my attempts to protect my database from mySQL injection I have created another problem for myself
Multiple includes losing variables
Hey all,
just starting out w php and ran into a problem pretty quickly. I'm
including seve
array_combine() trouble w/csv file
I have a problem with a piece of code I wrote to import some records from a csv file into mysql. I h
Help with Password Encoding/Decoding?
Trying to design a "change password" tool. On my signup code I'm using base64_encode, now
search query in mysql in php problem
my search query wont work, i know, that my codes are correct.please help
Code: [Select]&l
PHP switch function help
Hi, I am trying to create a search function for a directory website. On the search function on html
rookie looking for help coding a CSS form with PHP
I'm trying to figure out how to add PHP code to my xhtml form so that it is a working form embedded
get url?
how do i get the url of the page i'm currently on, on my website.. i think its get header.. how do i