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);
Did you know?Explore Trending and Topic pages for more stories like this.

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 Like 16 Dislike
Previous forums Next forums
Other forums

b+ tree
Hi
can every body help me about b+ tree ?(insert & delete)

Multiple Dropdown Selections
I have a form that let's a user insert a page with the ability to select categories. I want them to

i want run some web server under the ip sharer
hello i want run some web server under the ip sharer
my ip is floating ip but it doesnt matter

Php mysql - select?
Hi i have this code:
Code: $iteminfo = mysql_query("SELECT desc FROM wc_items WHERE itemid =

no idea what to do...
I'm fed up. I had issues with code that I have working on a different site that didn't work on my cu

PECL uploadprogress for php5.2
Hey, I just installed PHP5 via .htaccess on my 1and1 Shared Hosting Account.

How would I exac

Need understanding of this bit of code
Code: <?php
// WHERE clause filters
$arrSQLFilters = array();

//

Clean URLs
Hi I was wandering if anyone has ever implemented URLs on their PHP run website using URLS like wiki

Need help making a blockquote and line items conditional
I have some code I bought a few years ago that allows my clients to update content on their site usi

Displaying image pathname instead of image
Hello

Im trying to upload and then display images from a mysql database - Its only basic and

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash