2014-03-31 108 views
0

我無法找到任何有關閱讀電子郵件附件的文檔。任何人都可以提出建議ZF2閱讀電子郵件附件

我使用Zend\Mail\Storage\Imap來閱讀我的電子郵件文本,但我找不到任何方法來獲取附件。

回答

0

我已經找到一種方法來保存所有附件:

$attachment_files = array(); 
foreach (new \RecursiveIteratorIterator($message) as $part) { 
    try { 
     if (strtok($part->contentType, ';') == 'text/plain' || 
      strtok($part->contentType, ';') == 'text/html') { 
      $foundPart = $part; 
     } else { 
      $filename = $part->getHeaderField('Content-Description'); 
      $extention = pathinfo($filename, PATHINFO_EXTENSION); 
      $new_filename = ROOT_PATH . '/data/tmp/' . uniqid() . '.' . $extention; 
      $content = base64_decode($part->getContent()); 
      $fh = fopen($new_filename, 'w'); 
      fwrite($fh, $content); 
      fclose($fh); 
      $attachment_files[] = $new_filename; 
     } 
    } 
    catch (\Exception $e) { 
     // ignore 
    } 
} 

文件名被放在Content-Description頭,我節省了不屬於文本的所有部分。