private function examinePart(&$email, $part)
    {
        //echo '<br />'.$part->part_id.' '.$part->type.' '.$part->dparameters[0]->value;
        //get subtype JPEG, WAV, HTML, PLAIN, etc
        $subtype = \strtolower($part->subtype);

        //get encoding 0 = 7bit, 1= 8bit, 2=binary, 3=base64, 4=quoted prinatble, 5=other
        $encoding = $part->encoding;

        switch ($subtype) {

            case 'plain':
                if (empty($email->body)) {
                    $email->body_encoding = $encoding;
                    $email->body = imap_fetchbody($this->inbox, $email->index, $part->part_id);
                }
                break;

            case 'html':
                $email->body_HTML = imap_fetchbody($this->inbox, $email->index, $part->part_id);
                break;

            case 'applefile':
            case 'gif':
            case 'png':
            case 'jpg':
            case 'jpeg':
            case 'wav':
            case 'mp3':
            case 'mp4':
            case 'flv':

                if ($part->type == 5) {
                    $attachment = new Email_Attachment();
                    $attachment->sizeK = $part->bytes / 1000;
                    $attachment->subtype = $subtype;
                    $attachment->type = $part->type;
                    $attachment->name = $part->dparameters[0]->value;
                    //change jpeg into jpg
                    $attachment->name = \str_ireplace('jpeg', 'jpg', $attachment->name);
                    $attachment->extension = \strtolower(end(explode(".", $attachment->name)));

                    $attachment->contents = \imap_fetchbody($this->inbox, $email->index, $part->part_id);

                    //decode base64 contents
                    if ($part->encoding == 3) {
                        $attachment->contents = \imap_base64($attachment->contents);
                    }

                    $attachment->encoding = $part->encoding;
                    $email->attachments[] = $attachment;
                }
        }
    }