2013-07-31 4 views
-1

Я пытаюсь прочитать заголовки запроса на получение и приоритет от заголовков электронной почты через PHP.PHP: imap_header не отображает заголовки запроса и приоритета запроса

Кажется, что imap_header отображает только заголовки. Заголовки сообщений ниже следует, но не включают в себя два заголовка я ищу ...

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] => <[email protected]> 
[message_id] => <[email protected]> 
[toaddress] => [email protected] [to] => 
    Array ( 
    [0] => stdClass Object (
    [mailbox] => __ [host] => example.com 
    ) 
) 

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

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

[senderaddress] => Someone <[email protected]> 
[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 я могу использовать, чтобы перебирать ВСЕХ заголовков?

Бонус вверх: укажите полезный заголовок и ПОЧЕМУ он полезен в качестве комментария.

ответ

0

Фигурного это массив ниже возвращает всех заголовков, размещение для других ...

[править] Обновлено так, чтобы заголовки, которые могут появляться несколько раз проверяются и массив с их значениями добавлены. Массив $unlimited отбирается от http://tools.ietf.org/html/rfc5322#section-3.6. [/ edit]

<?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>'; 
?> 
Смежные вопросы