Line 1... |
Line 1... |
1 |
<?php
|
1 |
<?php
|
- |
|
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
- |
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
- |
|
4 |
// | PHP version 4.1 |
|
- |
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
- |
|
6 |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
|
- |
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
- |
|
8 |
// | This library is free software; you can redistribute it and/or |
|
- |
|
9 |
// | modify it under the terms of the GNU General Public |
|
- |
|
10 |
// | License as published by the Free Software Foundation; either |
|
- |
|
11 |
// | version 2.1 of the License, or (at your option) any later version. |
|
- |
|
12 |
// | |
|
- |
|
13 |
// | This library is distributed in the hope that it will be useful, |
|
- |
|
14 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
- |
|
15 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
- |
|
16 |
// | General Public License for more details. |
|
- |
|
17 |
// | |
|
- |
|
18 |
// | You should have received a copy of the GNU General Public |
|
- |
|
19 |
// | License along with this library; if not, write to the Free Software |
|
- |
|
20 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
- |
|
21 |
// +------------------------------------------------------------------------------------------------------+
|
- |
|
22 |
// CVS : $Id: ezmlm-parser.php,v 1.3 2007-04-19 15:34:35 neiluj Exp $
|
- |
|
23 |
/**
|
- |
|
24 |
* Application projet
|
- |
|
25 |
*
|
- |
|
26 |
* classe ezmlm_parser pour lire les fichiers d index de ezmlm-idx
|
- |
|
27 |
*
|
- |
|
28 |
*@package projet
|
- |
|
29 |
//Auteur original : ?? recupere dans ezmlm-php
|
- |
|
30 |
*@author Alexandre Granier <alexandre@tela-botanica.org>
|
- |
|
31 |
*@copyright Tela-Botanica 2000-2004
|
- |
|
32 |
*@version $Revision: 1.3 $
|
- |
|
33 |
// +------------------------------------------------------------------------------------------------------+
|
- |
|
34 |
*/
|
- |
|
35 |
|
- |
|
36 |
|
- |
|
37 |
// +------------------------------------------------------------------------------------------------------+
|
- |
|
38 |
// | ENTETE du PROGRAMME |
|
- |
|
39 |
// +------------------------------------------------------------------------------------------------------+
|
- |
|
40 |
|
2 |
// $Id: ezmlm-parser.php,v 1.2 2005-09-27 16:43:08 alexandre_tb Exp $
|
41 |
// $Id: ezmlm-parser.php,v 1.3 2007-04-19 15:34:35 neiluj Exp $
|
3 |
//
|
42 |
//
|
4 |
// ezmlm-parser.php - ezmlm-php v2.0
|
- |
|
5 |
// --------------------------------------------------------------
|
- |
|
6 |
// Contains all the code for parsing messages.
|
- |
|
7 |
// It handles all the nessesary decoding, attachments, etc...
|
- |
|
8 |
// Note this does all the parsing itself now removing the dependancy
|
- |
|
9 |
// on the mailparse library (as it looks like it will never make
|
- |
|
10 |
// it into the official inclusion with PHP)...
|
- |
|
11 |
// --------------------------------------------------------------
|
- |
|
Line 12... |
Line 43... |
12 |
|
43 |
|
13 |
require_once("ezmlm.php");
|
44 |
require_once("ezmlm.php");
|
14 |
require_once("Mail/mimeDecode.php") ;
|
45 |
require_once("Mail/mimeDecode.php") ;
|
15 |
// CLASS: ezmlm-parser
|
46 |
// CLASS: ezmlm-parser
|
16 |
class ezmlm_parser extends ezmlm_php {
|
47 |
class ezmlm_parser extends ezmlm_php {
|
17 |
var $headers; // the full untouched headers of the message
|
48 |
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)
|
49 |
var $body; // the full untouched (but decoded) body (this is not $this->parts[0]->body)
|
Line 19... |
Line 50... |
19 |
var $parts; // all the parts, if it is a multipart message. each part is an ezmlm_parser object...
|
50 |
var $parts; // all the parts, if it is a multipart message. each part is an ezmlm_parser object...
|
20 |
|
51 |
|
21 |
// Here's the most accessed headers, everything else can be
|
52 |
// Here's the most accessed headers, everything else can be
|
22 |
// accessed from the $this->headers array.
|
53 |
// accessed from the $this->headers array.
|
23 |
var $to; // To:
|
54 |
var $to; // To:
|
24 |
var $from; // From:
|
55 |
var $from; // From:
|
25 |
var $date; // Date:
|
56 |
var $date; // Date:
|
26 |
var $subject; // Subject:
|
57 |
var $subject; // Subject:
|
Line 27... |
Line 58... |
27 |
var $replyto; // Reply-To:
|
58 |
var $replyto; // Reply-To:
|
Line 28... |
Line 59... |
28 |
var $contenttype; // Content-Type:
|
59 |
var $contenttype; // Content-Type:
|
Line 29... |
Line 60... |
29 |
|
60 |
|
Line -... |
Line 61... |
- |
|
61 |
var $multipart; // TRUE if the message is a multipart message
|
30 |
var $multipart; // TRUE if the message is a multipart message
|
62 |
|
- |
|
63 |
var $msgfile; // if parsed from a file, this is the filename...
|
- |
|
64 |
|
- |
|
65 |
// functions
|
- |
|
66 |
|
- |
|
67 |
/**
|
- |
|
68 |
* recent_msgs renvoie les derniers messages de la liste de discussion
|
- |
|
69 |
* ezmlm
|
- |
|
70 |
*
|
- |
|
71 |
* (
|
- |
|
72 |
* [0] => Array
|
- |
|
73 |
* (
|
- |
|
74 |
* [1] => sujet
|
- |
|
75 |
* [2] => date en anglais
|
- |
|
76 |
* [3] => le hash de l auteur
|
- |
|
77 |
* [4] => l auteur
|
- |
|
78 |
* )
|
31 |
|
79 |
* [1] => ...
|
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 80... |
79 |
if ($temp != "") { $cursubject = $temp; }
|
80 |
* )
|
80 |
}
|
81 |
* @param int le nombre de message a renvoye
|
81 |
fclose($fd);
|
82 |
* @return array un tableau contenant les messages
|
82 |
|
83 |
* @access public
|
83 |
list($msgnum,$fromthread,$authorid) = split(":",$cursubject);
|
84 |
*/
|
84 |
$msgdir = (int)($msgnum / 100); // on reconstruit le répertoire du message en divisant son numéro par 100
|
85 |
function recent_msgs($show = 20, $month = "") {
|
85 |
|
86 |
|
- |
|
87 |
$repertoire_archive = opendir($this->listdir . "/archive/");
|
86 |
$numshown = 0;
|
88 |
|
- |
|
89 |
$repertoire_message = array() ;
|
87 |
|
90 |
$dernier_repertoire = 0 ;
|
88 |
$msgfiles = array();
|
91 |
while (false !== ($item = readdir($repertoire_archive))) {
|
- |
|
92 |
// $item contient les noms des repertoires
|
89 |
// on boucle 100 fois
|
93 |
// on ne garde que ceux qui sont des chiffres
|
- |
|
94 |
|
- |
|
95 |
if (preg_match('/[0-9]+/', $item)) {
|
90 |
for ($i = 0; $i <= 99; $i++) {
|
96 |
// on ouvre le fichier d index de chaque repertoire
|
91 |
if (($msgdir == 0) and ($i == 0)) { $i++; };
|
97 |
if ((int) $item > $dernier_repertoire) $dernier_repertoire = (int) $item;
|
- |
|
98 |
|
92 |
if ($i < 10) { $msgfile = "0" . $i; }
|
99 |
}
|
- |
|
100 |
}
|
- |
|
101 |
$tableau_message = array() ;
|
- |
|
102 |
$compteur_message = 0 ;
|
93 |
else { $msgfile = $i; }
|
103 |
$fichier_index = fopen ($this->listdir.'/archive/'.$dernier_repertoire.'/index', 'r') ;
|
- |
|
104 |
while (!feof($fichier_index)) {
|
94 |
if (!is_file($this->listdir . "/archive/" . $msgdir . "/" . $msgfile)) { break; }
|
105 |
// Recuperation du numero de message, du hash du sujet et du sujet
|
- |
|
106 |
$temp = fgets($fichier_index, 4096);
|
- |
|
107 |
preg_match('/([0-9]+): ([a-z]+) (.*)/', $temp, $match) ;
|
95 |
|
108 |
|
96 |
}
|
109 |
// dans la seconde on recupere la date, hash auteur et auteur
|
- |
|
110 |
$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
|
111 |
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) {
|
112 |
if ($match[1] != '') {
|
- |
|
113 |
$tableau_message[$match[1]] = array ($match[2], $match[3],
|
- |
|
114 |
$match_deuxieme_ligne[1].' '.$match_deuxieme_ligne[2].' '.$match_deuxieme_ligne[3],
|
- |
|
115 |
$match_deuxieme_ligne[5],
|
- |
|
116 |
$match_deuxieme_ligne[6]);
|
- |
|
117 |
}
|
- |
|
118 |
}
|
- |
|
119 |
fclose ($fichier_index);
|
- |
|
120 |
// on renverse le tableau pour afficher les derniers messages en premier
|
99 |
$i--;
|
121 |
$tableau_message = array_reverse($tableau_message, true);
|
- |
|
122 |
|
- |
|
123 |
// On compte le nombre de message, s il est inferieur $show et que l on est
|
100 |
if ($i < 0) {
|
124 |
// pas dans le premier index, on ouvre le fichier precedent et recupere
|
- |
|
125 |
// le n dernier message
|
101 |
$i = 99;
|
126 |
|
- |
|
127 |
if (count ($tableau_message) < $show && $dernier_repertoire != '0') {
|
- |
|
128 |
$avant_dernier_repertoire = $dernier_repertoire - 1 ;
|
- |
|
129 |
// On utilise file_get_contents pour renverser le fichier
|
- |
|
130 |
$fichier_index = array_reverse(
|
- |
|
131 |
explode ("\n",
|
- |
|
132 |
preg_replace ('/\n$/', '',
|
- |
|
133 |
file_get_contents ($this->listdir.'/archive/'.$avant_dernier_repertoire.'/index')) ), true) ;
|
- |
|
134 |
reset ($fichier_index);
|
- |
|
135 |
//var_dump ($fichier_index);
|
- |
|
136 |
|
- |
|
137 |
for ($i = count ($tableau_message); $i <= $show; $i++) {
|
- |
|
138 |
// Recuperation du numero de message, du hash du sujet et du sujet
|
- |
|
139 |
// dans la seconde on recupere la date, hash auteur et auteur
|
- |
|
140 |
|
- |
|
141 |
preg_match('/\t([0-9]+) ([a-zA-Z][a-zA-Z][a-zA-Z]) ([0-9][0-9][0-9][0-9]) ([^;]+);([^ ]*) (.*)/',
|
- |
|
142 |
current ($fichier_index), $match_deuxieme_ligne) ;
|
- |
|
143 |
preg_match('/([0-9]+): ([a-z]+) (.*)/', next($fichier_index), $match) ;
|
- |
|
144 |
next ($fichier_index);
|
102 |
$msgdir--;
|
145 |
|
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)) {
|
146 |
if ($match[1] != '') {
|
116 |
$msgfile = $this->listdir . "/" . $msgfile;
|
- |
|
117 |
} else if (is_file($this->listdir . "/archive/" . $msgfile)) {
|
147 |
$tableau_message[$match[1]] = array ($match[2], $match[3],
|
118 |
$msgfile = $this->listdir . "/archive/" . $msgfile;
|
- |
|
119 |
} else {
|
- |
|
120 |
return $msgfiles;
|
148 |
$match_deuxieme_ligne[1].' '.$match_deuxieme_ligne[2].' '.$match_deuxieme_ligne[3],
|
121 |
}
|
- |
|
122 |
}
|
- |
|
123 |
$message = file_get_contents($msgfile) ;
|
- |
|
124 |
$mimeDecode = new Mail_mimeDecode($message) ;
|
- |
|
125 |
$mailDecode = $mimeDecode->decode() ;
|
149 |
$match_deuxieme_ligne[5],
|
- |
|
150 |
$match_deuxieme_ligne[6]);
|
126 |
$mailDecode->msgfile = $msgfile ;
|
151 |
}
|
127 |
$mailDecode->nummessage = $msgdir.$i ;
|
152 |
}
|
128 |
$msgfiles[] = $mailDecode ;
|
153 |
} else {
|
Line 129... |
Line 154... |
129 |
|
154 |
// Si le nombre de message est > $show on limite le tableau de retour
|
130 |
unset($mailDecode);
|
155 |
$tableau_message = array_slice($tableau_message, 0, $show, true);
|
Line 149... |
Line 174... |
149 |
while (!feof($fd)) { $data .= fgets($fd,4096); }
|
174 |
while (!feof($fd)) { $data .= fgets($fd,4096); }
|
150 |
fclose($fd);
|
175 |
fclose($fd);
|
151 |
return $this->parse($data,$simple);
|
176 |
return $this->parse($data,$simple);
|
152 |
}
|
177 |
}
|
Line 153... |
Line 178... |
153 |
|
178 |
|
154 |
// parse_file_headers - ouvre un fichier et analyse les entêtes
|
179 |
// parse_file_headers - ouvre un fichier et analyse les entête
|
155 |
function parse_file_headers($file,$simple = FALSE) {
|
180 |
function parse_file_headers($file,$simple = FALSE) {
|
156 |
if (!is_file($file)) {
|
181 |
if (!is_file($file)) {
|
157 |
if (is_file($this->listdir . "/" . $file)) { $file = $this->listdir . "/" . $file; }
|
182 |
if (is_file($this->listdir . "/" . $file)) { $file = $this->listdir . "/" . $file; }
|
158 |
else if (is_file($this->listdir . "/archive/" . $file)) { $file = $this->listdir . "/archive/" . $file; }
|
183 |
else if (is_file($this->listdir . "/archive/" . $file)) { $file = $this->listdir . "/archive/" . $file; }
|
Line 163... |
Line 188... |
163 |
$data = file_get_contents ($file) ;
|
188 |
$data = file_get_contents ($file) ;
|
164 |
$message = file_get_contents($file) ;
|
189 |
$message = file_get_contents($file) ;
|
165 |
$mimeDecode = new Mail_mimeDecode($message) ;
|
190 |
$mimeDecode = new Mail_mimeDecode($message) ;
|
166 |
$mailDecode = $mimeDecode->decode() ;
|
191 |
$mailDecode = $mimeDecode->decode() ;
|
167 |
return $mailDecode ;
|
192 |
return $mailDecode ;
|
168 |
/*$fd = fopen($file, "r");
|
- |
|
169 |
while (!feof($fd)) { $data .= fgets($fd,4096); }
|
- |
|
170 |
fclose($fd);*/
|
- |
|
171 |
if ($this->_get_headers($data, $simple)) return true ;
|
- |
|
172 |
return false ;
|
- |
|
173 |
}
|
193 |
}
|
Line 174... |
Line 194... |
174 |
|
194 |
|
175 |
// this does all of the work (well it calls two functions that do all the work :)
|
195 |
// this does all of the work (well it calls two functions that do all the work :)
|
176 |
// all the decoding a part breaking follows RFC2045 (http://www.faqs.org/rfcs/rfc2045.html)
|
196 |
// all the decoding a part breaking follows RFC2045 (http://www.faqs.org/rfcs/rfc2045.html)
|