<?PHP
$headers=imap_fetchheader($imap, $msgid);
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $headers, $matches);
?>
Works quite well for splitting headers,
$matches will contain 3 arrays:
$matches[0] are the full-lines (To: Jille@devnull.quis.cx\r\n)
$matches[1] will be the header (To)
$matches[2] will be the value (Jille@devnull.quis.cx)
In multi-line values the 'multilining is not stripped!'
this could be achieved with something like:
<?PHP
preg_replace('/\r\n\s+/m', '', $matches[2]);
?>
imap_fetchheader
(PHP 4, PHP 5)
imap_fetchheader — Devuelve la cabecera de un mensaje
Descripción
string imap_fetchheader
( resource $secuencia_imap
, int $numero_mensaje
[, int $opciones
] )
Esta función produce la recuperación de la cabecera completa, sin filtrar, en formato » RFC2822 del mensaje especificado.
Lista de parámetros
- imap_stream
-
An IMAP stream returned by imap_open().
- numero_mensaje
-
El número de mensaje
- opciones
-
Las posibles opciones son:
- FT_UID - El argumento num_mensaje es un UID
- FT_INTERNAL - La cadena de retorno está en formato "interno", sin intento alguno de moldear a nuevas líneas tipo CRLF
- FT_PREFETCHTEXT - El archivo RFC822.TEXT debe ser pre-solicitado al mismo tiempo. Esto evita un RTT extra en una conexión IMAP si se desea un mensaje de texto completo (p.ej. en la operación "guardar a archivo local")
Valores retornados
Devuelve la cabecera del mensaje especificado como una cadena de texto.
imap_fetchheader
Jille at nomorecrap dot quis dot cx
07-Apr-2008 12:15
07-Apr-2008 12:15
onofabio at gmail dot com
07-Mar-2008 12:18
07-Mar-2008 12:18
This function ignore that some header value have multiple lines...
<?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
?>
I write this simple function....
$mbox = imap_open("{localhost:143/imap}INBOX", "your_username", "your_password");
$mid=1 // Message id
// Get headers
$header = imap_fetchheader($mbox, $mid);
// Split on \n
$h_array=split("\n",$header);
foreach ( $h_array as $h ) {
// Check if row start with a char
if ( preg_match("/^[A-Z]/i", $h )) {
$tmp = split(":",$h);
$header_name = $tmp[0];
$header_value = $tmp[1];
$headers[$header_name] = $header_value;
} else {
// Append row to previous field
$headers[$header_name] = $header_value . $h;
}
}
Max Geiger
09-Mar-2007 12:59
09-Mar-2007 12:59
If you call the function with the bitmask-parameter FT_PREFETCHTEXT the /Seen flag of the message will be set.
dj_doktor at upskirt dot cz
03-Apr-2005 04:17
03-Apr-2005 04: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
?>
