For people just beging this may help alot as I spent a couple hours just trying to relize how exact the array was stored. (at the time I did not know the print_r function :P)
$struct = imap_fetchstructure($mbox, $msgnumber);
print_r($struct);
Will give you a better example for your messages but they are called as $struct using the varible method above.
$struct->type; //would return the type
$struct->encoding //would return the encoding
and etc..
This can be done many different ways but that is the basics on pulling the info out of the structure of fetchstructure itself, I hope it helps someone starting because it wouldve helped me :/.