douhuang3740 2014-02-18 18:24
浏览 88
已采纳

PHP IMAP获取签名附件

I have problem with parsing email message with PHP IMAP. Problem is that I have message signed with pkcs#7 signature. Mail contains some text and 2 attachments first one is smime.p7s and second one is message.htm which is html attachment I would like to parse.

To be honest I have no idea how can I access content of this file.

    $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;
        }
    }

I get full structure and I can find there part:

       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"
            }
          }
        }

Can anyone give me a hint how can I access content of message.htm ?

  • 写回答

1条回答 默认 最新

  • douzhang5199 2014-02-18 18:36
    关注

    Since the structure does not have any parts defined, then the message is "simple".

    Try using:

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

    This will fetch the "0th" part of the message, which should be the body.

    Check out the docs here: http://www.php.net/manual/en/function.imap-fetchstructure.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。