2012-09-04 135 views
0

我遇到了一些Zend Framework問題,並從GMAIL獲取附件。認證由oAuth處理。Zend_Mail - 從GMAIL獲取IMAP附件

這是獲取Mailtext沒有問題,但我不能獲取attachement,或者更好,我不知道如何做到這一點(;

從我的郵件
 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; 
       } 
      } 

頁眉(去掉了一些細節):

[delivered-to] => [email protected] 
[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 

回答

1

我還沒有嘗試過,但如果它的工作原理,你欠我一杯啤酒......不管怎麼說,試試這個:按道理它應該工作...

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); 

如果u得到錯誤,它張貼在這裏

,或者如果它的工作原理,給我打勾)

+0

感謝,但如何識別有一個附件? (看看我的貼子例子)。或者每次都是第2部分的附件? – opHASnoNAME

+0

我編輯了我的答案:P是啊,似乎你有一個附件,因爲:[content-type] => multipart/mixed; boundary = f46d043bd88a9f5d9404c87d2ad5 – Karma

+0

那麼,會發生什麼?你試過我的腳本?期望打字錯誤,因爲我剛剛打字而沒有測試... – Karma