imap_fetchheader

(PHP 3 >= 3.0.3, PHP 4, PHP 5)

imap_fetchheader -- Returns header for a message

Description

string imap_fetchheader ( resource imap_stream, int msgno [, int options] )

This function causes a fetch of the complete, unfiltered RFC2822 format header of the specified message as a text string and returns that text string.

The options are:

  • FT_UID - The msgno argument is a UID

  • FT_INTERNAL - The return string is in "internal" format, without any attempt to canonicalize to CRLF newlines

  • FT_PREFETCHTEXT - The RFC822.TEXT should be pre-fetched at the same time. This avoids an extra RTT on an IMAP connection if a full message text is desired (e.g. in a "save to local file" operation)


add a note add a note User Contributed Notes
dj_doktor at upskirt dot cz
03-Apr-2005 10:17
I spend lot of time find out how I can detect messages with
different priorities. When I read users notes I remember
function imap_fetchheader which show header of message
and additional headers too. Because I'm so lazy to work with
regular expressions I required my frend for writing code
- thanx Znouza.
And there is... :)

<?php
  
// connecting to imap mailserver
  
$connection = @imap_open("{localhost:143/imap}INBOX", "your_username", "your_password");

  
// get imap_fetch header and put single lines into array
  
$header = explode("\n", imap_fetchheader($connection, 1));

  
// browse array for additional headers
  
if (is_array($header) && count($header)) {
      
$head = array();
       foreach(
$header as $line) {
          
// is line with additional header?
          
if (eregi("^X-", $line)) {
              
// separate name and value
              
eregi("^([^:]*): (.*)", $line, $arg);
              
$head[$arg[1]] = $arg[2];
           }
       }
   }

  
// now are all contained additional headers in array $head
?>