Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 1335 → Rev 1336

/trunk/client/projet/classes/ezmlm-php-2.0/ezmlm-parser.php
1,31 → 1,62
<?php
// $Id: ezmlm-parser.php,v 1.2 2005-09-27 16:43:08 alexandre_tb Exp $
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public |
// | License as published by the Free Software Foundation; either |
// | version 2.1 of the License, or (at your option) any later version. |
// | |
// | This library is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public |
// | License along with this library; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: ezmlm-parser.php,v 1.3 2007-04-19 15:34:35 neiluj Exp $
/**
* Application projet
*
* classe ezmlm_parser pour lire les fichiers d index de ezmlm-idx
*
*@package projet
//Auteur original : ?? recupere dans ezmlm-php
*@author Alexandre Granier <alexandre@tela-botanica.org>
*@copyright Tela-Botanica 2000-2004
*@version $Revision: 1.3 $
// +------------------------------------------------------------------------------------------------------+
*/
 
 
// +------------------------------------------------------------------------------------------------------+
// | ENTETE du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
 
// $Id: ezmlm-parser.php,v 1.3 2007-04-19 15:34:35 neiluj Exp $
//
// ezmlm-parser.php - ezmlm-php v2.0
// --------------------------------------------------------------
// Contains all the code for parsing messages.
// It handles all the nessesary decoding, attachments, etc...
// Note this does all the parsing itself now removing the dependancy
// on the mailparse library (as it looks like it will never make
// it into the official inclusion with PHP)...
// --------------------------------------------------------------
 
require_once("ezmlm.php");
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
 
33,105 → 64,99
 
// functions
 
// recent_msgs - parses and returns an arbitrary number of the most recent messages
/**
* recent_msgs renvoie les derniers messages de la liste de discussion
* ezmlm
*
* (
* [0] => Array
* (
* [1] => sujet
* [2] => date en anglais
* [3] => le hash de l auteur
* [4] => l auteur
* )
* [1] => ...
* )
* @param int le nombre de message a renvoye
* @return array un tableau contenant les messages
* @access public
*/
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++;
} else {
// Si le nombre de message est > $show on limite le tableau de retour
$tableau_message = array_slice($tableau_message, 0, $show, true);
}
return $msgfiles;
return $tableau_message ;
}
 
 
151,7 → 176,7
return $this->parse($data,$simple);
}
 
// parse_file_headers - ouvre un fichier et analyse les entêtes
// parse_file_headers - ouvre un fichier et analyse les entête
function parse_file_headers($file,$simple = FALSE) {
if (!is_file($file)) {
if (is_file($this->listdir . "/" . $file)) { $file = $this->listdir . "/" . $file; }
165,11 → 190,6
$mimeDecode = new Mail_mimeDecode($message) ;
$mailDecode = $mimeDecode->decode() ;
return $mailDecode ;
/*$fd = fopen($file, "r");
while (!feof($fd)) { $data .= fgets($fd,4096); }
fclose($fd);*/
if ($this->_get_headers($data, $simple)) return true ;
return false ;
}
 
// this does all of the work (well it calls two functions that do all the work :)