1,5 → 1,5 |
<?php |
// $Id: ezmlm-parser.php,v 1.2 2005-09-27 16:43:08 alexandre_tb Exp $ |
// $Id: ezmlm-parser.php,v 1.2.4.1 2007-03-12 11:22:12 alexandre_tb Exp $ |
// |
// ezmlm-parser.php - ezmlm-php v2.0 |
// -------------------------------------------------------------- |
14,18 → 14,18 |
require_once("Mail/mimeDecode.php") ; |
// CLASS: ezmlm-parser |
class ezmlm_parser extends ezmlm_php { |
var $headers; // the full untouched headers of the message |
var $body; // the full untouched (but decoded) body (this is not $this->parts[0]->body) |
var $headers; // the full untouched headers of the message |
var $body; // the full untouched (but decoded) body (this is not $this->parts[0]->body) |
var $parts; // all the parts, if it is a multipart message. each part is an ezmlm_parser object... |
|
// Here's the most accessed headers, everything else can be |
// accessed from the $this->headers array. |
var $to; // To: |
var $from; // From: |
var $date; // Date: |
var $subject; // Subject: |
var $replyto; // Reply-To: |
var $contenttype; // Content-Type: |
// Here's the most accessed headers, everything else can be |
// accessed from the $this->headers array. |
var $to; // To: |
var $from; // From: |
var $date; // Date: |
var $subject; // Subject: |
var $replyto; // Reply-To: |
var $contenttype; // Content-Type: |
|
var $multipart; // TRUE if the message is a multipart message |
|
35,103 → 35,77 |
|
// recent_msgs - parses and returns an arbitrary number of the most recent messages |
function recent_msgs($show = 20, $month = "") { |
if ($month == "") { $month = date("Ym"); } |
$threadyear = substr($month,0,4); |
$threadmonth = substr($month,4,2); |
|
$repertoire_archive = opendir($this->listdir . "/archive/"); |
|
if (!is_file($this->listdir . "/archive/threads/" . $month)) { |
if ($threadmonth == '01') { $prevthread = ($threadyear - 1) . "12"; } |
else if ($threadmonth >= 11) { $prevthread = $threadyear . ($threadmonth - 1); } |
else { $prevthread = $threadyear . "0" . ($threadmonth - 1); } |
return $this->recent_msgs($show,$prevthread); |
$repertoire_message = array() ; |
$dernier_repertoire = 0 ; |
while (false !== ($item = readdir($repertoire_archive))) { |
// $item contient les noms des repertoires |
// on ne garde que ceux qui sont des chiffres |
|
if (preg_match('/[0-9]+/', $item)) { |
// on ouvre le fichier d index de chaque repertoire |
if ((int) $item > $dernier_repertoire) $dernier_repertoire = (int) $item; |
|
} |
} |
// on ouvre les fichiers de threads du dernier mois |
$fd = fopen($this->listdir . "/archive/threads/" . $month, "r"); |
fseek($fd,-256,SEEK_END); |
|
// on récupère la dernière ligne |
|
while (!feof($fd)) { |
$temp = fgets($fd,4096); |
if ($temp != "") { $curthread = $temp; } |
} |
$nombre_message = 0 ; |
fseek ($fd, 0) ; |
while (!feof($fd)) { |
$nombre_message++; |
fgets($fd); |
} |
fclose($fd); |
///echo "<br />".$curthread."<br />" ; |
$subjectfile = preg_replace("/^[0-9]*\:([a-z]*) \[.*/", "\\1", $curthread); |
$subjectfile = substr($subjectfile,0,2) . "/" . substr($subjectfile,2,18); // on ne garde que les 2 1ère lettre du hash, slash et le reste du hash |
|
// on ouvre le fichier des sujets |
// présenté comme suit : |
// hash sujet originel (sur la première ligne) |
// num_message:annéemois:hash_auteur Nom Auteur |
$fd = fopen($this->listdir . "/archive/subjects/" . $subjectfile, "r"); |
fseek($fd,-512,SEEK_END); |
|
// on prend la dernière ligne |
while (!feof($fd)) { |
$temp = fgets($fd,4096); |
if ($temp != "") { $cursubject = $temp; } |
} |
fclose($fd); |
|
list($msgnum,$fromthread,$authorid) = split(":",$cursubject); |
$msgdir = (int)($msgnum / 100); // on reconstruit le répertoire du message en divisant son numéro par 100 |
$tableau_message = array() ; |
$compteur_message = 0 ; |
$fichier_index = fopen ($this->listdir.'/archive/'.$dernier_repertoire.'/index', 'r') ; |
while (!feof($fichier_index)) { |
// Recuperation du numero de message, du hash du sujet et du sujet |
$temp = fgets($fichier_index, 4096); |
preg_match('/([0-9]+): ([a-z]+) (.*)/', $temp, $match) ; |
|
// dans la seconde on recupere la date, hash auteur et auteur |
$temp = fgets($fichier_index, 4096); |
preg_match('/\t([0-9]+) ([a-zA-Z][a-zA-Z][a-zA-Z]) ([0-9][0-9][0-9][0-9]) ([^;]+);(.*) (.*)/', $temp, $match_deuxieme_ligne) ; |
if ($match[1] != '') { |
$tableau_message[$match[1]] = array ($match[2], $match[3], |
$match_deuxieme_ligne[1].' '.$match_deuxieme_ligne[2].' '.$match_deuxieme_ligne[3], |
$match_deuxieme_ligne[5], |
$match_deuxieme_ligne[6]); |
} |
} |
fclose ($fichier_index); |
// on renverse le tableau pour afficher les derniers messages en premier |
$tableau_message = array_reverse($tableau_message, true); |
|
$numshown = 0; |
|
$msgfiles = array(); |
// on boucle 100 fois |
for ($i = 0; $i <= 99; $i++) { |
if (($msgdir == 0) and ($i == 0)) { $i++; }; |
if ($i < 10) { $msgfile = "0" . $i; } |
else { $msgfile = $i; } |
if (!is_file($this->listdir . "/archive/" . $msgdir . "/" . $msgfile)) { break; } |
|
} |
if ($show == '') $show = $nombre_message ; // Si aucun paramètre n'est passé on renvoie tous les fichiers du mois |
while ($numshown < $show) { |
$i--; |
if ($i < 0) { |
$i = 99; |
$msgdir--; |
if ($msgdir < 0) { break; } |
// On compte le nombre de message, s il est inferieur $show et que l on est |
// pas dans le premier index, on ouvre le fichier precedent et recupere |
// le n dernier message |
|
if (count ($tableau_message) < $show && $dernier_repertoire != '0') { |
$avant_dernier_repertoire = $dernier_repertoire - 1 ; |
// On utilise file_get_contents pour renverser le fichier |
$fichier_index = array_reverse( |
explode ("\n", |
preg_replace ('/\n$/', '', |
file_get_contents ($this->listdir.'/archive/'.$avant_dernier_repertoire.'/index')) ), true) ; |
reset ($fichier_index); |
//var_dump ($fichier_index); |
|
for ($i = count ($tableau_message); $i <= $show; $i++) { |
// Recuperation du numero de message, du hash du sujet et du sujet |
// dans la seconde on recupere la date, hash auteur et auteur |
|
preg_match('/\t([0-9]+) ([a-zA-Z][a-zA-Z][a-zA-Z]) ([0-9][0-9][0-9][0-9]) ([^;]+);(.*) (.*)/', |
current ($fichier_index), $match_deuxieme_ligne) ; |
preg_match('/([0-9]+): ([a-z]+) (.*)/', next($fichier_index), $match) ; |
next ($fichier_index); |
|
if ($match[1] != '') { |
$tableau_message[$match[1]] = array ($match[2], $match[3], |
$match_deuxieme_ligne[1].' '.$match_deuxieme_ligne[2].' '.$match_deuxieme_ligne[3], |
$match_deuxieme_ligne[5], |
$match_deuxieme_ligne[6]); |
} |
} |
if ($i < 10) { |
$msgfile = $this->listdir . "/archive/" . $msgdir . "/0" . $i; |
} else { |
$msgfile = $this->listdir . "/archive/" . $msgdir . "/" . $i; |
} |
/* |
$msg = new ezmlm_parser(); |
$msg->parse_file($msgfile); |
*/ |
if (!is_file($msgfile)) { |
if (is_file($this->listdir . "/" . $msgfile)) { |
$msgfile = $this->listdir . "/" . $msgfile; |
} else if (is_file($this->listdir . "/archive/" . $msgfile)) { |
$msgfile = $this->listdir . "/archive/" . $msgfile; |
} else { |
return $msgfiles; |
} |
} |
$message = file_get_contents($msgfile) ; |
$mimeDecode = new Mail_mimeDecode($message) ; |
$mailDecode = $mimeDecode->decode() ; |
$mailDecode->msgfile = $msgfile ; |
$mailDecode->nummessage = $msgdir.$i ; |
$msgfiles[] = $mailDecode ; |
|
unset($mailDecode); |
$numshown++; |
} |
|
return $msgfiles; |
|
|
return ($tableau_message) ; |
} |
|
|