dsn1327 2013-07-31 01:54
浏览 57
已采纳

PHP:imap_header不显示请求读取收据和优先级标头

I'm trying to read the Request Read Receipt and Priority headers from email headers via PHP.

IT seems that imap_header only displays select headers. The message headers below should but do not include the two headers I'm looking for...

 stdClass Object ( 
 [date] => Tue, 30 Jul 2013 18:11:26 -0700 (MST)
 [Date] => Tue, 30 Jul 2013 18:11:26 -0700 (MST) 
 [subject] => Return
 Request Receipt + High Priority Test 
 [Subject] => Return Request
 Receipt + High Priority Test 
 [in_reply_to] => <__@mrmail.com>
 [message_id] => <__@mrmail.com> 
 [toaddress] => __@example.com [to] =>
   Array ( 
   [0] => stdClass Object (
     [mailbox] => __ [host] => example.com
   )
 )

 [fromaddress] => Someone <__@mrmail.com> 
 [from] => 
   Array ( 
     [0] =>
       stdClass Object ( 
         [personal] => Someone 
         [mailbox] => example 
         [host] => mrmail.com 
   )
 )

 [reply_toaddress] => Someone <__@mrmail.com> 
 [reply_to] => 
   Array ( 
     [0] => stdClass Object (
       [personal] => Someone 
       [mailbox] => __ 
       [host] => mrmail.com 
      )
 )

 [senderaddress] => Someone <__@mrmail.com> 
 [sender] => 
   Array ( 
     [0] => stdClass Object ( 
       [personal] => Someone 
       [mailbox] => example 
       [host] => mrmail.com 
      )
 )

 [Recent] => 
 [Unseen] => U 
 [Flagged] => 
 [Answered] => 
 [Deleted] =>
 [Draft] => 
 [Msgno] => 69 
 [MailDate] => 30-Jul-2013 19:18:03 -0600
 [Size] => 2719 
 [udate] => 1375233483

So what function in PHP do I use to iterate through ALL headers?

  • 写回答

1条回答 默认 最新

  • dongyi4420 2013-08-02 18:12
    关注

    Figured it out, the array below returns all headers, posting for others...

    [edit] Updated so that headers that may appear more than once are checked and an array with their values are added. The $unlimited array is sampled from http://tools.ietf.org/html/rfc5322#section-3.6.[/edit]

    <?php
    $th = imap_fetchheader($mbox,$cms->page2);
    $th = trim($th);
    $th = str_ireplace("","
    ",$th);
    $th = str_ireplace("
    
    ","
    ",$th);
    $p0 = explode("
    ",$th);
    $current = '';
    $unlimited = array('comments','keywords','optional-field','resent-bcc','resent-cc','resent-date','resent-from','resent-msg-id','resent-sender','resent-to','trace');
    $headers = array();
    
    foreach ($p0 as $k1)
    {
     $k1 = rtrim($k1);
     $a = $k1;
     $b = trim($k1);
    
     if ($a!==$b)
     {
      $p1 = trim($k1);
      if (in_array($current,$unlimited)) {array_push($headers[strtolower($current)],$p1);}
      else {$headers[strtolower($current)] .= $p1;}
     }
     else if (stristr($k1,':'))
     {
      $p1 = explode(':',$k1,2);
      if (in_array(strtolower($p1[0]),$unlimited))
      {
       if (!isset($headers[strtolower($p1[0])])) {$headers[strtolower($p1[0])] = array($p1[1]);}
       else {array_push($headers[strtolower($current)],$p1[1]);}
      }
      else
      {
       if (!isset($headers[strtolower($p1[0])])) {$headers[strtolower($p1[0])] = $p1[1];}
       else {$headers[strtolower($p1[0])] .= $p1[1];}
      }
    
      $current = $p1[0];
     }
    }
    
    ksort($headers);//Mainly for testing purposes, remove this afterwards.
    
    echo '<div><pre>';
    $a = print_r($headers,1);
    echo htmlspecialchars($a).'</pre></div>';
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度