Subversion Repositories Applications.papyrus

Rev

Rev 1087 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1087 Rev 1253
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 33... Line 33...
33
 
33
 
Line 34... Line 34...
34
	// functions
34
	// functions
35
 
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);
-
 
79
			if ($temp != "") { $cursubject = $temp; }
-
 
80
		}
-
 
81
		fclose($fd);
-
 
82
	
-
 
83
		list($msgnum,$fromthread,$authorid) = split(":",$cursubject);
-
 
84
		$msgdir = (int)($msgnum / 100); // on reconstruit le répertoire du message en divisant son numéro par 100
-
 
85
		
-
 
86
		$numshown = 0;
-
 
87
        
-
 
88
		$msgfiles = array();
-
 
89
        // on boucle 100 fois
-
 
90
		for ($i = 0; $i <= 99; $i++) {
-
 
91
			if (($msgdir == 0) and ($i == 0)) { $i++; };
-
 
92
			if ($i < 10) { $msgfile = "0" . $i; }
-
 
93
			else { $msgfile = $i; }
-
 
94
			if (!is_file($this->listdir . "/archive/" . $msgdir . "/" . $msgfile)) { break; }
-
 
95
            
-
 
96
		}
-
 
97
        if ($show == '') $show = $nombre_message ;  // Si aucun paramètre n'est passé on renvoie tous les fichiers du mois
-
 
98
		while ($numshown < $show) {
-
 
99
			$i--;
-
 
100
			if ($i < 0) {
-
 
101
				$i = 99;
-
 
102
				$msgdir--;
-
 
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() ;
-
 
126
            $mailDecode->msgfile = $msgfile ;
-
 
Line -... Line 36...
-
 
36
	// recent_msgs - parses and returns an arbitrary number of the most recent messages
-
 
37
	function recent_msgs($show = 20, $month = "") {
-
 
38
		
-
 
39
		$repertoire_archive = opendir($this->listdir . "/archive/");
-
 
40
 
-
 
41
		$repertoire_message = array() ;
-
 
42
		$dernier_repertoire = 0 ;
-
 
43
		while (false !== ($item = readdir($repertoire_archive))) {
-
 
44
			// $item contient les noms des repertoires
-
 
45
			// on ne garde que ceux qui sont des chiffres
-
 
46
 
-
 
47
			if (preg_match('/[0-9]+/', $item)) {
-
 
48
				// on ouvre le fichier d index de chaque repertoire
-
 
49
				if ((int) $item > $dernier_repertoire) $dernier_repertoire = (int) $item;
-
 
50
			
-
 
51
			}
-
 
52
		}
-
 
53
		$tableau_message = array() ;
-
 
54
		$compteur_message = 0 ;
-
 
55
		$fichier_index = fopen ($this->listdir.'/archive/'.$dernier_repertoire.'/index', 'r') ;
-
 
56
		while (!feof($fichier_index)) {
-
 
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) ;
-
 
60
				
-
 
61
				// dans la seconde on recupere la date, hash auteur et auteur
-
 
62
				$temp = fgets($fichier_index, 4096);
-
 
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) ;
-
 
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
-
 
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
-
 
76
		// pas dans le premier index, on ouvre le fichier precedent et recupere
-
 
77
		// le n dernier message
-
 
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(
127
            $mailDecode->nummessage = $msgdir.$i ;
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
 
128
			$msgfiles[] = $mailDecode ;
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);
-
 
97
				
-
 
98
				if ($match[1] != '') {
-
 
99
				$tableau_message[$match[1]] = array ($match[2], $match[3], 
-
 
100
									$match_deuxieme_ligne[1].' '.$match_deuxieme_ligne[2].' '.$match_deuxieme_ligne[3], 
129
            
101
									$match_deuxieme_ligne[5], 
-
 
102
									$match_deuxieme_ligne[6]);
-
 
103
				}
Line 130... Line 104...
130
			unset($mailDecode);
104
			}
131
			$numshown++;
105
		}
Line 132... Line 106...
132
		}
106
			
133
        
107