| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
// $Id: ezmlm-parser.php,v 1.2 2005-09-27 16:43:08 alexandre_tb Exp $
|
2 |
// $Id: ezmlm-parser.php,v 1.2.4.1 2007-03-12 11:22:12 alexandre_tb Exp $
|
| 3 |
//
|
3 |
//
|
| 4 |
// ezmlm-parser.php - ezmlm-php v2.0
|
4 |
// ezmlm-parser.php - ezmlm-php v2.0
|
| 5 |
// --------------------------------------------------------------
|
5 |
// --------------------------------------------------------------
|
| 6 |
// Contains all the code for parsing messages.
|
6 |
// Contains all the code for parsing messages.
|
| 7 |
// It handles all the nessesary decoding, attachments, etc...
|
7 |
// It handles all the nessesary decoding, attachments, etc...
|
| Line 12... |
Line 12... |
| 12 |
|
12 |
|
| 13 |
require_once("ezmlm.php");
|
13 |
require_once("ezmlm.php");
|
| 14 |
require_once("Mail/mimeDecode.php") ;
|
14 |
require_once("Mail/mimeDecode.php") ;
|
| 15 |
// CLASS: ezmlm-parser
|
15 |
// CLASS: ezmlm-parser
|
| 16 |
class ezmlm_parser extends ezmlm_php {
|
16 |
class ezmlm_parser extends ezmlm_php {
|
| 17 |
var $headers; // the full untouched headers of the message
|
17 |
var $headers; // the full untouched headers of the message
|
| 18 |
var $body; // the full untouched (but decoded) body (this is not $this->parts[0]->body)
|
18 |
var $body; // the full untouched (but decoded) body (this is not $this->parts[0]->body)
|
| Line 19... |
Line 19... |
| 19 |
var $parts; // all the parts, if it is a multipart message. each part is an ezmlm_parser object...
|
19 |
var $parts; // all the parts, if it is a multipart message. each part is an ezmlm_parser object...
|
| 20 |
|
20 |
|
| 21 |
// Here's the most accessed headers, everything else can be
|
21 |
// Here's the most accessed headers, everything else can be
|
| 22 |
// accessed from the $this->headers array.
|
22 |
// accessed from the $this->headers array.
|
| 23 |
var $to; // To:
|
23 |
var $to; // To:
|
| 24 |
var $from; // From:
|
24 |
var $from; // From:
|
| 25 |
var $date; // Date:
|
25 |
var $date; // Date:
|
| 26 |
var $subject; // Subject:
|
26 |
var $subject; // Subject:
|
| Line 27... |
Line 27... |
| 27 |
var $replyto; // Reply-To:
|
27 |
var $replyto; // Reply-To:
|
| Line 28... |
Line 28... |
| 28 |
var $contenttype; // Content-Type:
|
28 |
var $contenttype; // Content-Type:
|
| Line 29... |
Line 29... |
| 29 |
|
29 |
|
| Line 30... |
Line 30... |
| 30 |
var $multipart; // TRUE if the message is a multipart message
|
30 |
var $multipart; // TRUE if the message is a multipart message
|
| 31 |
|
31 |
|
| 32 |
var $msgfile; // if parsed from a file, this is the filename...
|
- |
|
| 33 |
|
- |
|
| 34 |
// functions
|
- |
|
| 35 |
|
- |
|
| 36 |
// recent_msgs - parses and returns an arbitrary number of the most recent messages
|
- |
|
| 37 |
function recent_msgs($show = 20, $month = "") {
|
- |
|
| 38 |
if ($month == "") { $month = date("Ym"); }
|
- |
|
| 39 |
$threadyear = substr($month,0,4);
|
- |
|
| 40 |
$threadmonth = substr($month,4,2);
|
- |
|
| 41 |
|
- |
|
| 42 |
if (!is_file($this->listdir . "/archive/threads/" . $month)) {
|
- |
|
| 43 |
if ($threadmonth == '01') { $prevthread = ($threadyear - 1) . "12"; }
|
- |
|
| 44 |
else if ($threadmonth >= 11) { $prevthread = $threadyear . ($threadmonth - 1); }
|
- |
|
| 45 |
else { $prevthread = $threadyear . "0" . ($threadmonth - 1); }
|
- |
|
| 46 |
return $this->recent_msgs($show,$prevthread);
|
- |
|
| 47 |
}
|
- |
|
| 48 |
// on ouvre les fichiers de threads du dernier mois
|
- |
|
| 49 |
$fd = fopen($this->listdir . "/archive/threads/" . $month, "r");
|
- |
|
| 50 |
fseek($fd,-256,SEEK_END);
|
- |
|
| 51 |
|
- |
|
| 52 |
// on récupère la dernière ligne
|
- |
|
| 53 |
|
- |
|
| 54 |
while (!feof($fd)) {
|
- |
|
| 55 |
$temp = fgets($fd,4096);
|
- |
|
| 56 |
if ($temp != "") { $curthread = $temp; }
|
- |
|
| 57 |
}
|
- |
|
| 58 |
$nombre_message = 0 ;
|
- |
|
| 59 |
fseek ($fd, 0) ;
|
- |
|
| 60 |
while (!feof($fd)) {
|
- |
|
| 61 |
$nombre_message++;
|
- |
|
| 62 |
fgets($fd);
|
- |
|
| 63 |
}
|
- |
|
| 64 |
fclose($fd);
|
- |
|
| 65 |
///echo "<br />".$curthread."<br />" ;
|
- |
|
| 66 |
$subjectfile = preg_replace("/^[0-9]*\:([a-z]*) \[.*/", "\\1", $curthread);
|
- |
|
| 67 |
$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
|
- |
|
| 68 |
|
- |
|
| 69 |
// on ouvre le fichier des sujets
|
- |
|
| 70 |
// présenté comme suit :
|
- |
|
| 71 |
// hash sujet originel (sur la première ligne)
|
- |
|
| 72 |
// num_message:annéemois:hash_auteur Nom Auteur
|
- |
|
| 73 |
$fd = fopen($this->listdir . "/archive/subjects/" . $subjectfile, "r");
|
- |
|
| 74 |
fseek($fd,-512,SEEK_END);
|
- |
|
| 75 |
|
- |
|
| 76 |
// on prend la dernière ligne
|
- |
|
| 77 |
while (!feof($fd)) {
|
- |
|
| 78 |
$temp = fgets($fd,4096);
|
- |
|
| Line 79... |
Line 32... |
| 79 |
if ($temp != "") { $cursubject = $temp; }
|
32 |
var $msgfile; // if parsed from a file, this is the filename...
|
| 80 |
}
|
33 |
|
| 81 |
fclose($fd);
|
34 |
// functions
|
| 82 |
|
35 |
|
| 83 |
list($msgnum,$fromthread,$authorid) = split(":",$cursubject);
|
36 |
// recent_msgs - parses and returns an arbitrary number of the most recent messages
|
| 84 |
$msgdir = (int)($msgnum / 100); // on reconstruit le répertoire du message en divisant son numéro par 100
|
37 |
function recent_msgs($show = 20, $month = "") {
|
| 85 |
|
38 |
|
| - |
|
39 |
$repertoire_archive = opendir($this->listdir . "/archive/");
|
| 86 |
$numshown = 0;
|
40 |
|
| - |
|
41 |
$repertoire_message = array() ;
|
| 87 |
|
42 |
$dernier_repertoire = 0 ;
|
| 88 |
$msgfiles = array();
|
43 |
while (false !== ($item = readdir($repertoire_archive))) {
|
| - |
|
44 |
// $item contient les noms des repertoires
|
| 89 |
// on boucle 100 fois
|
45 |
// on ne garde que ceux qui sont des chiffres
|
| - |
|
46 |
|
| - |
|
47 |
if (preg_match('/[0-9]+/', $item)) {
|
| 90 |
for ($i = 0; $i <= 99; $i++) {
|
48 |
// on ouvre le fichier d index de chaque repertoire
|
| 91 |
if (($msgdir == 0) and ($i == 0)) { $i++; };
|
49 |
if ((int) $item > $dernier_repertoire) $dernier_repertoire = (int) $item;
|
| - |
|
50 |
|
| 92 |
if ($i < 10) { $msgfile = "0" . $i; }
|
51 |
}
|
| - |
|
52 |
}
|
| - |
|
53 |
$tableau_message = array() ;
|
| - |
|
54 |
$compteur_message = 0 ;
|
| 93 |
else { $msgfile = $i; }
|
55 |
$fichier_index = fopen ($this->listdir.'/archive/'.$dernier_repertoire.'/index', 'r') ;
|
| - |
|
56 |
while (!feof($fichier_index)) {
|
| 94 |
if (!is_file($this->listdir . "/archive/" . $msgdir . "/" . $msgfile)) { break; }
|
57 |
// Recuperation du numero de message, du hash du sujet et du sujet
|
| - |
|
58 |
$temp = fgets($fichier_index, 4096);
|
| - |
|
59 |
preg_match('/([0-9]+): ([a-z]+) (.*)/', $temp, $match) ;
|
| 95 |
|
60 |
|
| 96 |
}
|
61 |
// dans la seconde on recupere la date, hash auteur et auteur
|
| - |
|
62 |
$temp = fgets($fichier_index, 4096);
|
| 97 |
if ($show == '') $show = $nombre_message ; // Si aucun paramètre n'est passé on renvoie tous les fichiers du mois
|
63 |
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) ;
|
| 98 |
while ($numshown < $show) {
|
64 |
if ($match[1] != '') {
|
| - |
|
65 |
$tableau_message[$match[1]] = array ($match[2], $match[3],
|
| - |
|
66 |
$match_deuxieme_ligne[1].' '.$match_deuxieme_ligne[2].' '.$match_deuxieme_ligne[3],
|
| - |
|
67 |
$match_deuxieme_ligne[5],
|
| - |
|
68 |
$match_deuxieme_ligne[6]);
|
| - |
|
69 |
}
|
| - |
|
70 |
}
|
| - |
|
71 |
fclose ($fichier_index);
|
| - |
|
72 |
// on renverse le tableau pour afficher les derniers messages en premier
|
| 99 |
$i--;
|
73 |
$tableau_message = array_reverse($tableau_message, true);
|
| - |
|
74 |
|
| - |
|
75 |
// On compte le nombre de message, s il est inferieur $show et que l on est
|
| 100 |
if ($i < 0) {
|
76 |
// pas dans le premier index, on ouvre le fichier precedent et recupere
|
| - |
|
77 |
// le n dernier message
|
| 101 |
$i = 99;
|
78 |
|
| - |
|
79 |
if (count ($tableau_message) < $show && $dernier_repertoire != '0') {
|
| - |
|
80 |
$avant_dernier_repertoire = $dernier_repertoire - 1 ;
|
| - |
|
81 |
// On utilise file_get_contents pour renverser le fichier
|
| - |
|
82 |
$fichier_index = array_reverse(
|
| - |
|
83 |
explode ("\n",
|
| - |
|
84 |
preg_replace ('/\n$/', '',
|
| - |
|
85 |
file_get_contents ($this->listdir.'/archive/'.$avant_dernier_repertoire.'/index')) ), true) ;
|
| - |
|
86 |
reset ($fichier_index);
|
| - |
|
87 |
//var_dump ($fichier_index);
|
| - |
|
88 |
|
| - |
|
89 |
for ($i = count ($tableau_message); $i <= $show; $i++) {
|
| - |
|
90 |
// Recuperation du numero de message, du hash du sujet et du sujet
|
| - |
|
91 |
// dans la seconde on recupere la date, hash auteur et auteur
|
| - |
|
92 |
|
| - |
|
93 |
preg_match('/\t([0-9]+) ([a-zA-Z][a-zA-Z][a-zA-Z]) ([0-9][0-9][0-9][0-9]) ([^;]+);(.*) (.*)/',
|
| - |
|
94 |
current ($fichier_index), $match_deuxieme_ligne) ;
|
| - |
|
95 |
preg_match('/([0-9]+): ([a-z]+) (.*)/', next($fichier_index), $match) ;
|
| - |
|
96 |
next ($fichier_index);
|
| 102 |
$msgdir--;
|
97 |
|
| 103 |
if ($msgdir < 0) { break; }
|
- |
|
| 104 |
}
|
- |
|
| 105 |
if ($i < 10) {
|
- |
|
| 106 |
$msgfile = $this->listdir . "/archive/" . $msgdir . "/0" . $i;
|
- |
|
| 107 |
} else {
|
- |
|
| 108 |
$msgfile = $this->listdir . "/archive/" . $msgdir . "/" . $i;
|
- |
|
| 109 |
}
|
- |
|
| 110 |
/*
|
- |
|
| 111 |
$msg = new ezmlm_parser();
|
- |
|
| 112 |
$msg->parse_file($msgfile);
|
- |
|
| 113 |
*/
|
- |
|
| 114 |
if (!is_file($msgfile)) {
|
- |
|
| 115 |
if (is_file($this->listdir . "/" . $msgfile)) {
|
- |
|
| 116 |
$msgfile = $this->listdir . "/" . $msgfile;
|
- |
|
| 117 |
} else if (is_file($this->listdir . "/archive/" . $msgfile)) {
|
- |
|
| 118 |
$msgfile = $this->listdir . "/archive/" . $msgfile;
|
- |
|
| 119 |
} else {
|
- |
|
| 120 |
return $msgfiles;
|
- |
|
| 121 |
}
|
- |
|
| 122 |
}
|
- |
|
| 123 |
$message = file_get_contents($msgfile) ;
|
- |
|
| 124 |
$mimeDecode = new Mail_mimeDecode($message) ;
|
- |
|
| 125 |
$mailDecode = $mimeDecode->decode() ;
|
98 |
if ($match[1] != '') {
|
| - |
|
99 |
$tableau_message[$match[1]] = array ($match[2], $match[3],
|
| 126 |
$mailDecode->msgfile = $msgfile ;
|
100 |
$match_deuxieme_ligne[1].' '.$match_deuxieme_ligne[2].' '.$match_deuxieme_ligne[3],
|
| 127 |
$mailDecode->nummessage = $msgdir.$i ;
|
101 |
$match_deuxieme_ligne[5],
|
| 128 |
$msgfiles[] = $mailDecode ;
|
102 |
$match_deuxieme_ligne[6]);
|
| Line 129... |
Line 103... |
| 129 |
|
103 |
}
|
| 130 |
unset($mailDecode);
|
104 |
}
|