473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

PHP IMAP Attachment issue

I have a bit of code that when using POP in the imap_open connect
string it will return the filenames of the attachments, but when using
IMAP it does not.

Been racking my brain over this for a week now and decided to ask in
here for some help.

CODE:
// open mailbox
$inbox = @imap_open("{" . $SESSION_EMAILSERVER .
"/imap:143/notls/novalidate-cert}", $SESSION_USERNAME,
$SESSION_PASSWORD) or die("Could not open Mailbox - try again later!");

// parse message body
function parse($structure)
{
global $type;
global $encoding;
// create an array to hold message sections
$ret = array();
// split structure into parts
$parts = $structure->parts;

for($x=0; $x<sizeof($parts); $x++)
{
$ret[$x]["pid"] = ($x+1);
$this = $parts[$x];
// default to text
if ($this->type == "") { $this->type = 0; }
$ret[$x]["type"] = $type[$this->type] . "/" .
strtolower($this->subtype);
// default to 7bit
if ($this->encoding == "") { $this->encoding = 0; }
$ret[$x]["encoding"] = $encoding[$this->encoding];
$ret[$x]["size"] = strtolower($this->bytes);
$ret[$x]["disposition"] = strtolower($this->disposition);
if (strtolower($this->disposition) == "attachment")
{
$params = $this->dparameters;
foreach ($params as $p)
{
if($p->attribute == "FILENAME")
{
$ret[$x]["name"] = $p->value;
break;
}
}
}
}
return $ret;
}

// iterate through object returned by parse()
// create a new array holding information only on message attachments
function get_attachments($arr)
{
for($x=0; $x<sizeof($arr); $x++)
{
if($arr[$x]["disposition"] == "attachment")
{
$ret[] = $arr[$x];
}
}
return $ret;
}

// get message headers and structure
$headers = imap_header($inbox, $id);
$structure = imap_fetchstructure($inbox, $id);

// if multipart, parse
if(sizeof($structure->parts) 1)
{
$sections = parse($structure);
$attachments = get_attachments($sections);
}

// if attachments exist
if (is_array($attachments))
{
// display as list
for($x=0; $x<sizeof($attachments); $x++)
{
echo "<li><a href=download.php?id=$id&pid=" . $attachments[$x]["pid"]
.. ">" . $attachments[$x]["name"] . " (" .
ceil($attachments[$x]["size"]/1024) . " KB)</a>";
}
}

Any help is greatly appreciated. TIA
slim

Aug 4 '06 #1
0 2175

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Fabian Müller | last post by:
Hello, I would like to access (open) my remote IMAP Mailbox with the imap_open() function in PHP Version 5.0.4. The Mailbox is located at the german provider freenet.de. The imap_open()...
0
by: dekoffie | last post by:
Hello there, I'm trying to create a connection with an IMAP server which is secured through SSL. I can get the connection just fine, and I get a first respone from the server. But then I send...
2
by: comp.lang.php | last post by:
Hi all, I am having a mail client script, which will read and send mail to mail server, using IMAP. When i am sending mail with attachment through forwarding, the attachment is not getting...
4
by: elyob | last post by:
Hi, I'm looking to setup an email system that will log into a catchall account, read to addresses and forward them to a different email address stored in a MySQL table. I may also allow the users...
0
by: Kevin F | last post by:
Sorry to repost... but 4am didn't get much responses. I've been trying to implement this script, it polls an IMAP inbox for unread messages and displays the sender and subject in a scrollable...
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
1
by: nitinpatel1117 | last post by:
Hi, i'm using php's imap extension to read emails from a mailbox. My php script has been working fine and i'm pretty sure that there is nothing wrong with it. here is extracts from my code ...
3
by: kpfunf | last post by:
I have the following code that works in accessing my personal folder inbox and subfolders. Option Explicit Sub SaveAttachmentsToFolder() On Error GoTo SaveAttachmentsToFolder_err ' Declare...
1
by: kathiresan | last post by:
Hi I'm trying a windows service that fetches the contents of the mails from my inbox and saves them in a database using IMAP protocol. I've fetched the contents of the mail body using the IMAP...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.