Zend Mail - 从GMAIL获取IMAP附件

I habe some trouble with Zend Framework and fetching Attachements from GMAIL. Authentication is handeld by oAuth.

It is no problem to fetch the Mailtext, but i cant fetch the attachement, or better i have no idea how to do it (;

        if ($message->isMultiPart()) {

            $iParts = $message->countParts();

            for ($i = 1; $i < $iParts; $i++) {
                $part = $message->getPart($i);

                // ATTACHEMENT?
                if () {
                    // DO MAIL DOWNLOAD
                }

                // MAIL TEXT
                if (strtok($part->contentType, ';') == 'text/plain') {
                    $encoding = $part->getHeader('content-transfer-encoding');
                    $contentType = $part->getHeader('content-type');
                    $content = $part->getContent();
                    break;
                } 
            }

Header from my mail (removed some details):

[delivered-to] => xxxx@gmail.com
[received] => Array
    (
        [0] => 
        [1] => 
        [2] => 
        [3] => 
    )
[return-path] => 
[received-spf] => 
[authentication-results] => 
[dkim-signature] =>
[mime-version] => 1.0
[from] => 
[date] => Thu, 30 Aug 2012 17:16:37 +0200
[message-id] => 
[subject] => ANHANG
[to] => 
[content-type] => multipart/mixed; boundary=f46d043bd88a9f5d9404c87d2ad5

I haven't tried it but, if it works, you owe me a beer... Anyways, Try this: Logically it should work...

if ($message->isMultiPart()) {
     $part = $message->getPart(2);
}

       // Remember mails with attachment are MULTI-part? (:
       $filename = $part->getHeader('content-description');
       $attachment = base64_decode($part->getContent()); //we decode because mails are encoded with base 64

       // File operations
       $fh = fopen($filename, 'w');
       fwrite($fh, $attachment);
       fclose($fh);

If u get error, post it here

or if it works, gimme a tick ;)