I am trying to get the mimetype and subtype of an attachment but am unable to using this code :

echo $mb =@imap_open("{$server:143}",$user,$pass)
or die("Unable to open connectio");
echo imap_num_msg($mb);
$struct = imap_fetchstructure($mb,$index);

while( list(,$sub) = each($struct->parts) ){
echo $sub->bytes."<BR>";
}
echo "<BR>".$struct->type;


foreach($struct->parts as $val)
echo $val;

Can someone point me in the right direction