2014-02-18 39 views
0

我有解析電子郵件與PHP IMAP問題。問題是我有消息用pkcs#7簽名簽名。郵件包含一些文本和2個附件,第一個是smime.p7s,第二個是message.htm,這是html附件我想解析。PHP IMAP獲得簽名附件

說實話我不知道如何訪問此文件的內容。

$hostname = '{host}INBOX'; 
    $username = 'name'; 
    $password = 'pass'; 
    /* try to connect */ 
    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); 
    /* grab emails */ 
    $emails = imap_search($inbox,'UNSEEN'); 
    $msg = Array(); 
    if($emails) { 
     /* begin output var */ 
     $output = ''; 

     /* put the newest emails on top */ 
     rsort($emails); 
     /* for every email... */ 
     foreach($emails as $email_number) { 
      $overview = imap_fetch_overview($inbox,$email_number,0); 
      $message = imap_fetchbody($inbox,$email_number,2); 
      $structure = imap_fetchstructure ($inbox,$email_number,FT_UID); 
      echo "<pre>"; 
      var_dump($structure); 
      echo "</pre>"; 
      break; 
     } 
    } 

我得到完整結構,我可以發現有部分:

 object(stdClass)#16 (14) { 
      ["type"]=> 
      int(0) 
      ["encoding"]=> 
      int(4) 
      ["ifsubtype"]=> 
      int(1) 
      ["subtype"]=> 
      string(4) "HTML" 
      ["ifdescription"]=> 
      int(0) 
      ["ifid"]=> 
      int(0) 
      ["lines"]=> 
      int(123) 
      ["bytes"]=> 
      int(4473) 
      ["ifdisposition"]=> 
      int(1) 
      ["disposition"]=> 
      string(10) "attachment" 
      ["ifdparameters"]=> 
      int(1) 
      ["dparameters"]=> 
      array(1) { 
      [0]=> 
      object(stdClass)#17 (2) { 
       ["attribute"]=> 
       string(8) "filename" 
       ["value"]=> 
       string(37) "message.htm" 
      } 
      } 
      ["ifparameters"]=> 
      int(1) 
      ["parameters"]=> 
      array(2) { 
      [0]=> 
      object(stdClass)#18 (2) { 
       ["attribute"]=> 
       string(4) "name" 
       ["value"]=> 
       string(37) "message.htm" 
      } 
      [1]=> 
      object(stdClass)#19 (2) { 
       ["attribute"]=> 
       string(7) "charset" 
       ["value"]=> 
       string(8) "us-ascii" 
      } 
      } 
     } 

誰能給我一個提示,我怎麼可以訪問的內容message.htm

+0

你試過之後''的var_dump($結構)''的var_dump($消息)? – willoller

+0

是的,我解碼後我得到了一些'base64'編碼的字符串,我得到一些用'VeriSign'編碼的隨機符號我猜 – Mithrand1r

+0

嘗試用'imap_body(...)'替換'imap_fetchbody(...)' – willoller

回答