PHP IMAP获取签名附件

时间:2014-02-18 18:24:31

标签: php imap

我在使用PHP IMAP解析电子邮件时遇到问题。问题是我有用pkcs#7签名签名的消息。邮件包含一些文字和2个附件,其中一个是smime.p7s,第二个是message.htm,这是html我要解析的附件。

说实话,我不知道如何访问此文件的内容。

    $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的内容?

1 个答案:

答案 0 :(得分:1)

由于结构没有定义任何parts,因此消息是&#34;简单&#34;。

尝试使用:

$message = imap_fetchbody($inbox,$email_number,0);

这将获取&#34; 0th&#34;消息的一部分,应该是正文。

点击此处的文档:http://www.php.net/manual/en/function.imap-fetchstructure.php