By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 909 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

unsupported body type in imap

100+
P: 111
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

[PHP]$mbox = imap_open ($host, $login, $password) or die("can't connect: " . imap_last_error());
$message_count = imap_num_msg($mbox);

for ($jk = $message_count; ($message_count-6) <= $jk; $jk--)
{
$structure = imap_fetchstructure($mbox, $jk , FT_UID);
$parts = $structure->parts;

for($i = 1; $i < count($parts); $i++)
{
$part = $parts[$i];

if($part->disposition == "ATTACHMENT")
{
// some more code here
}
}
}[/PHP]


Basically the code above is meant to read attachments from emails in a mailbox and save the attached files in the current working directory of the script that is running this code.

This is done by getting the

[PHP]$part->type;[/PHP]
of the email to identify the primary body type of the attached file and then read accordingly.

The primary body type is meant to be between 0 and 7, (imap_fetchstructure ), however i'm getting a primary body type of 9, which is totally messing things up becuase i can't seem to read this file successfully.


Also when reading emails, we are supposed to ignore the first element of the array. i.e in the above code

[PHP]$parts[0];[/PHP]
is meant to be ignored and we should start reading from

[PHP]$parts[1];[/PHP]

however in the email that i'm getting with the weird primary body type the attachment seems to be in the
[PHP]$parts[0];[/PHP]
element of the array, which also seems odd.


The attachmenat is meant to be a (.csv) file, and i can open the attachment using outlook 2003, therefore, i know that the attached file is not corrupted and is properly intact.
Does anyone know why i would recieve such a primary body type, or experienced this before, and know of any way that i can get around this so that i can read the attached file.

any help would be great.
Dec 10 '07 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821

Post your reply

Sign in to post your reply or Sign up for a free account.