首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP: imap_header不显示请求已读回执和优先级标题

PHP: imap_header不显示请求已读回执和优先级标题
EN

Stack Overflow用户
提问于 2013-07-31 09:54:13
回答 1查看 593关注 0票数 -1

我正在尝试通过PHP从电子邮件标题中读取请求的已读回执和优先级标题。

看起来imap_header只显示精选的标题。下面的邮件头应该但不包括我正在寻找的两个头...

代码语言:javascript
复制
 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

那么,我应该使用PHP中的哪个函数来迭代所有的头文件呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-03 02:12:30

弄清楚了,下面的数组返回所有的标题,为其他人张贴……

edit已更新,以便检查可能出现多次的标头,并添加包含其值的数组。从https://www.rfc-editor.org/rfc/rfc5322#section-3.6./edit中采样$unlimited数组

代码语言:javascript
复制
<?php
$th = imap_fetchheader($mbox,$cms->page2);
$th = trim($th);
$th = str_ireplace("\r","\n",$th);
$th = str_ireplace("\n\n","\n",$th);
$p0 = explode("\n",$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>';
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17960331

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档