Subversion Repositories Applications.projet

Rev

Rev 208 | Rev 253 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 208 Rev 249
1
<?php
1
<?php
2
// $Id: ezmlm-msgdisplay.php,v 1.4 2007-04-19 15:34:35 neiluj Exp $
2
// $Id: ezmlm-msgdisplay.php,v 1.5 2007-06-25 12:15:07 alexandre_tb Exp $
3
//
3
//
4
// ezmlm-msgdisplay.php - ezmlm-php v2.0
4
// ezmlm-msgdisplay.php - ezmlm-php v2.0
5
// --------------------------------------------------------------
5
// --------------------------------------------------------------
6
// Will parse a template (if specified) and display a message.
6
// Will parse a template (if specified) and display a message.
7
// Includes a default template.
7
// Includes a default template.
8
// --------------------------------------------------------------
8
// --------------------------------------------------------------
9
 
9
 
10
require_once("ezmlm.php");
10
require_once("ezmlm.php");
11
require_once("Mail/mimeDecode.php") ;
11
require_once("Mail/mimeDecode.php") ;
12
 
12
 
13
class ezmlm_msgdisplay extends ezmlm_php {
13
class ezmlm_msgdisplay extends ezmlm_php {
14
	// our template
14
	// our template
15
	var $msgtmpl;
15
	var $msgtmpl;
16
    var $message_rendu ;
16
    var $message_rendu ;
17
    var $_auth ;
17
    var $_auth ;
18
	// display: parses a message (using ezmlm_parser) and displays it
18
	// display: parses a message (using ezmlm_parser) and displays it
19
	// using a template
19
	// using a template
20
    var $msgfile;
20
    var $msgfile;
21
    
21
    
22
    function display($msgfile) {
22
    function display($msgfile) {
23
        if (!is_file($msgfile)) {
23
        if (!is_file($msgfile)) {
24
            if (is_file($this->listdir . "/" . $msgfile)) { $msgfile = $this->listdir . "/" . $msgfile; }
24
            if (is_file($this->listdir . "/" . $msgfile)) { $msgfile = $this->listdir . "/" . $msgfile; }
25
		else if (is_file($this->listdir . "/archive/" . $msgfile)) { $msgfile = $this->listdir . "/archive/" . $msgfile; }
25
		else if (is_file($this->listdir . "/archive/" . $msgfile)) { $msgfile = $this->listdir . "/archive/" . $msgfile; }
26
		else { return FALSE; }
26
		else { return FALSE; }
27
	    }
27
	    }
28
	$this->msgfile = $msgfile ;
28
	$this->msgfile = $msgfile ;
29
        $message = file_get_contents($msgfile) ;
29
        $message = file_get_contents($msgfile) ;
30
	// En cours de codage
30
	// En cours de codage
31
	// La fonction display retourne tout simplement le source du mail
31
	// La fonction display retourne tout simplement le source du mail
32
	// Il n'y a plus d'analyse à ce niveau
32
	// Il n'y a plus d'analyse à ce niveau
33
	
33
	
34
	return $message;
34
	return $message;
35
        $mimeDecode = new Mail_mimeDecode($message) ;
35
        $mimeDecode = new Mail_mimeDecode($message) ;
36
        $mailDecode = $mimeDecode->decode(array('decode_bodies' => 'true', 'include_bodies' => 'true')) ;
36
        $mailDecode = $mimeDecode->decode(array('decode_bodies' => 'true', 'include_bodies' => 'true')) ;
37
        
37
        
38
        // $msg->msgfile contient le chemin du fichier du mail en partant de la racine
38
        // $msg->msgfile contient le chemin du fichier du mail en partant de la racine
39
        // Le point d'exclamation est le délimiteur de l'expression régulière
39
        // Le point d'exclamation est le délimiteur de l'expression régulière
40
		$relfile = preg_replace('!' . $this->listdir . '!', '', $msgfile);
40
		$relfile = preg_replace('!' . $this->listdir . '!', '', $msgfile);
41
        
41
        
42
		$a1 = preg_replace('!/archive/(.*)/.*$!', '\1', $relfile);  // $a1 contient le nom du répertoire
42
		$a1 = preg_replace('!/archive/(.*)/.*$!', '\1', $relfile);  // $a1 contient le nom du répertoire
43
		$a2 = preg_replace('!/archive/.*/(.*)$!', '\1', $relfile);  // $a2 contient le nom du fichier
43
		$a2 = preg_replace('!/archive/.*/(.*)$!', '\1', $relfile);  // $a2 contient le nom du fichier
44
		if (isset($mailDecode->headers['date'])) $msgtime = strtotime(preg_replace ('/CEST/', '', $mailDecode->headers['date']));
44
		if (isset($mailDecode->headers['date'])) $msgtime = strtotime(preg_replace ('/CEST/', '', $mailDecode->headers['date']));
45
        $threadidx = date("Ym", $msgtime);
45
        $threadidx = date("Ym", $msgtime);
46
        if ($a2 <= 10) $numero_precedent = '0'.($a2 - 1) ; else $numero_precedent = ($a2 - 1) ;
46
        if ($a2 <= 10) $numero_precedent = '0'.($a2 - 1) ; else $numero_precedent = ($a2 - 1) ;
47
        if ($a2 < 9) $numero_suivant = '0'.($a2 + 1) ; else $numero_suivant =  ($a2 + 1);
47
        if ($a2 < 9) $numero_suivant = '0'.($a2 + 1) ; else $numero_suivant =  ($a2 + 1);
48
        // On teste si le message suivant existe
48
        // On teste si le message suivant existe
49
        $decoupe = explode ('/', $msgfile) ;
49
        $decoupe = explode ('/', $msgfile) ;
50
        
50
        
51
        // Les nom de fichiers sont du format :
51
        // Les nom de fichiers sont du format :
52
        // archive/0/01
52
        // archive/0/01
53
        // archive/0/02 ... 0/99 archive/1/01 ...
53
        // archive/0/02 ... 0/99 archive/1/01 ...
54
        
54
        
55
        $nom_fichier = $decoupe[count($decoupe)-1] ;
55
        $nom_fichier = $decoupe[count($decoupe)-1] ;
56
        $nom_repertoire = $decoupe[count($decoupe)-2] ;
56
        $nom_repertoire = $decoupe[count($decoupe)-2] ;
57
        $repertoire_suivant = $nom_repertoire ; $repertoire_precedent = $nom_repertoire ;
57
        $repertoire_suivant = $nom_repertoire ; $repertoire_precedent = $nom_repertoire ;
58
        if ($nom_fichier > 8) {
58
        if ($nom_fichier > 8) {
59
            $fichier_suivant = $nom_fichier + 1 ;
59
            $fichier_suivant = $nom_fichier + 1 ;
60
            if ($nom_fichier == 99) {
60
            if ($nom_fichier == 99) {
61
                $fichier_suivant = '01' ;
61
                $fichier_suivant = '01' ;
62
                $repertoire_suivant = $nom_repertoire + 1 ;
62
                $repertoire_suivant = $nom_repertoire + 1 ;
63
            }
63
            }
64
        } else {
64
        } else {
65
            $fichier_suivant = '0'.($nom_fichier + 1) ;
65
            $fichier_suivant = '0'.($nom_fichier + 1) ;
66
        }
66
        }
67
        if ($nom_fichier > 10) {
67
        if ($nom_fichier > 10) {
68
            $fichier_precedent = $nom_fichier - 1 ;
68
            $fichier_precedent = $nom_fichier - 1 ;
69
        } else {
69
        } else {
70
            if ($nom_fichier == '01') {
70
            if ($nom_fichier == '01') {
71
                $fichier_precedent = '99' ;
71
                $fichier_precedent = '99' ;
72
                $repertoire_precedent = $nom_repertoire - 1 ;
72
                $repertoire_precedent = $nom_repertoire - 1 ;
73
            } else {
73
            } else {
74
                $fichier_precedent = '0'.($nom_fichier - 1) ;
74
                $fichier_precedent = '0'.($nom_fichier - 1) ;
75
            }
75
            }
76
        }
76
        }
77
        print $this->parse_entete_mail($mailDecode) ;
77
        print $this->parse_entete_mail($mailDecode) ;
78
		$this->parse_template($mailDecode, $a2, $a1);
78
		$this->parse_template($mailDecode, $a2, $a1);
79
        print $this->message_rendu;
79
        print $this->message_rendu;
80
        //print '</div>' ;
80
        //print '</div>' ;
81
	}
81
	}
82
    
82
    
83
    /**
83
    /**
84
     * Renvoie les infos des messages suivants
84
     * Renvoie les infos des messages suivants
85
     * 
85
     * 
86
     *
86
     *
87
    */
87
    */
88
    function getInfoSuivant() {
88
    function getInfoSuivant() {
89
		$relfile = preg_replace('!' . $this->listdir . '!', '', $this->msgfile);
89
		$relfile = preg_replace('!' . $this->listdir . '!', '', $this->msgfile);
90
	 	$nom_repertoire = preg_replace('!/archive/(.*)/.*$!', '\1', $relfile);
90
	 	$nom_repertoire = preg_replace('!/archive/(.*)/.*$!', '\1', $relfile);
91
		$nom_fichier = preg_replace('!/archive/.*/(.*)$!', '\1', $relfile);
91
		$nom_fichier = preg_replace('!/archive/.*/(.*)$!', '\1', $relfile);
92
	       
92
	       
93
		$repertoire_suivant = $nom_repertoire;
93
		$repertoire_suivant = $nom_repertoire;
94
		
94
		
95
		// a partir du nom du fichier
95
		// a partir du nom du fichier
96
		// et du nom du repertoire, on reconstitue
96
		// et du nom du repertoire, on reconstitue
97
		// le numero du message stocke dans le fichier d index
97
		// le numero du message stocke dans le fichier d index
98
		// le message 12 du repertoire 2 a le numero 112
98
		// le message 12 du repertoire 2 a le numero 112
99
		
99
		
100
		if ($nom_repertoire == '0') {
100
		if ($nom_repertoire == '0') {
101
			$numero_message = $nom_fichier;
101
			$numero_message = $nom_fichier;
102
		} else {
102
		} else {
103
			$numero_message = $nom_repertoire.$nom_fichier ;
103
			$numero_message = $nom_repertoire.$nom_fichier ;
104
		}
104
		}
105
		
105
		
106
		// On ouvre le fichier d index
106
		// On ouvre le fichier d index
107
		$fichier_index = fopen ($this->listdir.'/archive/'.$nom_repertoire.'/index', 'r');
107
		$fichier_index = fopen ($this->listdir.'/archive/'.$nom_repertoire.'/index', 'r');
108
		
108
		
109
		
109
		
110
		$compteur_ligne = 1;
110
		$compteur_ligne = 1;
111
		if (preg_match ('/0([1-9][0-9]*)/', $nom_fichier, $match)) {
111
		if (preg_match ('/0([1-9][0-9]*)/', $nom_fichier, $match)) {
112
			$nom_fichier = $match[1];
112
			$nom_fichier = $match[1];
113
			$prefixe = '0' ;
113
			$prefixe = '0' ;
114
		} else {
114
		} else {
115
			$prefixe = '' ;
115
			$prefixe = '' ;
116
		}
116
		}
117
		$prefixe = $this->prefixe_nom_message($nom_fichier);
117
		$prefixe = $this->prefixe_nom_message($nom_fichier);
118
		//echo $numero_message;
118
		//echo $numero_message;
119
		// on cherche la ligne avec le numero du message
119
		// on cherche la ligne avec le numero du message
120
		while (!feof($fichier_index)) {
120
		while (!feof($fichier_index)) {
121
				
121
				
122
				$temp = fgets($fichier_index,4096);
122
				$temp = fgets($fichier_index,4096);
123
				list($num, $hash, $sujet) = split (':', $temp) ;
123
				list($num, $hash, $sujet) = split (':', $temp) ;
124
				
124
				
125
				if ($num == $numero_message) {
125
				if ($num == $numero_message) {
126
					
126
					
127
					$ligne_message_precedent = $compteur_ligne -2;
127
					$ligne_message_precedent = $compteur_ligne -2;
128
					$temp = fgets($fichier_index, 4096);
128
					$temp = fgets($fichier_index, 4096);
129
					$temp = fgets($fichier_index, 4096);
129
					$temp = fgets($fichier_index, 4096);
130
					list ($fichier_suivant,$hash, $sujet) = split(':', $temp);
130
					list ($fichier_suivant,$hash, $sujet) = split(':', $temp);
131
					
131
					
132
					// Au cas ou est au dernier message du fichier d index
132
					// Au cas ou est au dernier message du fichier d index
133
					// il faut ouvrir le suivant
133
					// il faut ouvrir le suivant
134
					if (feof($fichier_index)) {
134
					if (feof($fichier_index)) {
135
						$repertoire_suivant++;
135
						$repertoire_suivant++;
136
						if (file_exists($this->listdir.'/archive/'.$repertoire_suivant.'/index')) {
136
						if (file_exists($this->listdir.'/archive/'.$repertoire_suivant.'/index')) {
137
							$fichier_index_suivant = fopen($this->listdir.'/archive/'.$repertoire_suivant.'/index', 'r');
137
							$fichier_index_suivant = fopen($this->listdir.'/archive/'.$repertoire_suivant.'/index', 'r');
138
							// on recupere le numero du premier message
138
							// on recupere le numero du premier message
139
							list($fichier_suivant, $hash, $sujet) = split (':', fgets($fichier_index_suivant), 4096);
139
							list($fichier_suivant, $hash, $sujet) = split (':', fgets($fichier_index_suivant), 4096);
140
							fclose ($fichier_index_suivant);
140
							fclose ($fichier_index_suivant);
141
						}
141
						}
142
					}
142
					}
143
					
143
					
144
					// Si le numero est > 100, il faut decouper et ne retenir
144
					// Si le numero est > 100, il faut decouper et ne retenir
145
					// que les dizaines et unites
145
					// que les dizaines et unites
146
					if ($fichier_suivant >= 100) {
146
					if ($fichier_suivant >= 100) {
147
						$decimal = (string) $fichier_suivant;
147
						$decimal = (string) $fichier_suivant;
148
						$numero = substr($decimal, -2) ;
148
						$numero = substr($decimal, -2) ;
149
						$fichier_suivant = $numero ;
149
						$fichier_suivant = $numero ;
150
					} else {
150
					} else {
151
						if ($fichier_suivant < 9)$fichier_suivant = '0'.$fichier_suivant;
151
						if ($fichier_suivant <= 9)$fichier_suivant = '0'.$fichier_suivant;
152
					}
152
					}
153
					
153
					
154
					break;
154
					break;
155
				}
155
				}
156
				
156
				
157
				// On avance d une ligne, la 2e ligne contient date hash auteur
157
				// On avance d une ligne, la 2e ligne contient date hash auteur
158
				$temp2 = fgets($fichier_index, 4096);
158
				$temp2 = fgets($fichier_index, 4096);
159
				$compteur_ligne += 2;
159
				$compteur_ligne += 2;
160
		}
160
		}
161
		
161
		
162
		// On utilise $ligne_message_precedent pour recupere le num du message precedent
162
		// On utilise $ligne_message_precedent pour recupere le num du message precedent
163
		// Si $ligne_precedent est negatif soit c le premier message de la liste
163
		// Si $ligne_precedent est negatif soit c le premier message de la liste
164
		// soit il faut ouvrir le repertoire precedent 
164
		// soit il faut ouvrir le repertoire precedent 
165
		
165
		
166
		if ($ligne_message_precedent > 0) {
166
		if ($ligne_message_precedent > 0) {
167
			$compteur = 1;
167
			$compteur = 1;
168
			rewind($fichier_index);
168
			rewind($fichier_index);
169
			while (!feof($fichier_index)) {
169
			while (!feof($fichier_index)) {
170
				$temp = fgets($fichier_index, 4096);
170
				$temp = fgets($fichier_index, 4096);
171
				if ($ligne_message_precedent == $compteur) {
171
				if ($ligne_message_precedent == $compteur) {
172
					list ($fichier_precedent, $hash, $sujet) = split (':', $temp) ; 	
172
					list ($fichier_precedent, $hash, $sujet) = split (':', $temp) ; 	
173
				}
173
				}
174
				$compteur++;
174
				$compteur++;
175
			}
175
			}
176
			// Le nom du repertoire precedent est le meme que le repertoire courant
176
			// Le nom du repertoire precedent est le meme que le repertoire courant
177
			$repertoire_precedent = $nom_repertoire ;
177
			$repertoire_precedent = $nom_repertoire ;
178
		// Si $ligne_message_precedent est negatif, alors il faut ouvrir
178
		// Si $ligne_message_precedent est negatif, alors il faut ouvrir
179
		// le fichier index du repertoire precedent
179
		// le fichier index du repertoire precedent
180
		// si le nom du repertoire est 0, alors il n y a pas de repertoire precedent
180
		// si le nom du repertoire est 0, alors il n y a pas de repertoire precedent
181
		// et donc pas de message precedent
181
		// et donc pas de message precedent
182
		} else {
182
		} else {
183
			
183
			
184
			if ($nom_repertoire != '0') {
184
			if ($nom_repertoire != '0') {
185
				$repertoire_precedent = $nom_repertoire -1 ;
185
				$repertoire_precedent = $nom_repertoire -1 ;
186
				// on ouvre le fichier d index et on extraie le numero
186
				// on ouvre le fichier d index et on extraie le numero
187
				// du dernier message
187
				// du dernier message
188
				
188
				
189
				$fichier_index_precedent = fopen ($this->listdir.'/archive/'.$repertoire_precedent.'/index', 'r') ;
189
				$fichier_index_precedent = fopen ($this->listdir.'/archive/'.$repertoire_precedent.'/index', 'r') ;
190
				while (!feof($fichier_index_precedent)) {
190
				while (!feof($fichier_index_precedent)) {
191
					$temp = fgets($fichier_index_precedent,4096);
191
					$temp = fgets($fichier_index_precedent,4096);
192
					$ligne = split (':', $temp) ;
192
					$ligne = split (':', $temp) ;
193
					if ($ligne[0] != '') $fichier_precedent = $ligne[0];
193
					if ($ligne[0] != '') $fichier_precedent = $ligne[0];
194
					$temp = fgets($fichier_index_precedent,4096);
194
					$temp = fgets($fichier_index_precedent,4096);
195
				}
195
				}
196
				
196
				
197
				fclose ($fichier_index_precedent);
197
				fclose ($fichier_index_precedent);
198
			// on se situe dans le repertoire 0 donc pas de message precedent
198
			// on se situe dans le repertoire 0 donc pas de message precedent
199
			} else {
199
			} else {
200
				$fichier_precedent = null;
200
				$fichier_precedent = null;
201
				$repertoire_precedent = null;
201
				$repertoire_precedent = null;
202
			}
202
			}
203
		}
203
		}
204
		if ($fichier_precedent > 100) {
204
		if ($fichier_precedent > 100) {
205
			$decimal = (string) $fichier_precedent;
205
			$decimal = (string) $fichier_precedent;
206
			$numero = substr($decimal, -2) ;
206
			$numero = substr($decimal, -2) ;
207
			$fichier_precedent = $numero ;
207
			$fichier_precedent = $numero ;
208
		} else {
208
		} else {
209
			if ($fichier_precedent < 10 )$fichier_precedent = '0'.$fichier_precedent;
209
			if ($fichier_precedent < 10 )$fichier_precedent = '0'.$fichier_precedent;
210
		}
210
		}
211
		fclose ($fichier_index);
211
		fclose ($fichier_index);
212
		//if ($fichier_precedent != null && $fichier_precedent < 10) $fichier_precedent = '0'.$fichier_precedent;
212
		//if ($fichier_precedent != null && $fichier_precedent < 10) $fichier_precedent = '0'.$fichier_precedent;
213
	
213
	
214
		return array ('fichier_suivant' => $fichier_suivant,
214
		return array ('fichier_suivant' => $fichier_suivant,
215
			      'repertoire_suivant' => $repertoire_suivant,
215
			      'repertoire_suivant' => $repertoire_suivant,
216
			      'fichier_precedent' => $fichier_precedent,
216
			      'fichier_precedent' => $fichier_precedent,
217
			      'repertoire_precedent' => $repertoire_precedent);
217
			      'repertoire_precedent' => $repertoire_precedent);
218
	}
218
	}
219
	
219
	
220
    /**
220
    /**
221
    *   analyse l'entete d'un mail pour en extraire les entête
221
    *   analyse l'entete d'un mail pour en extraire les entête
222
    *   to, from, subject, date
222
    *   to, from, subject, date
223
    *   met à jour la variable $this->msgtmpl
223
    *   met à jour la variable $this->msgtmpl
224
    *
224
    *
225
    */
225
    */
226
    
226
    
227
    function parse_entete_mail (&$mailDecode) {
227
    function parse_entete_mail (&$mailDecode) {
228
        $startpos = strpos(strtolower($this->msgtmpl_entete), '<ezmlm-headers>');
228
        $startpos = strpos(strtolower($this->msgtmpl_entete), '<ezmlm-headers>');
229
        $endpos = strpos(strtolower($this->msgtmpl_entete), '</ezmlm-headers>');
229
        $endpos = strpos(strtolower($this->msgtmpl_entete), '</ezmlm-headers>');
230
		$headers = substr($this->msgtmpl_entete,$startpos + 15,($endpos - $startpos - 15));
230
		$headers = substr($this->msgtmpl_entete,$startpos + 15,($endpos - $startpos - 15));
231
        $headers_replace = '' ;
231
        $headers_replace = '' ;
232
		for ($i = 0; $i < count($this->showheaders); $i++) {
232
		for ($i = 0; $i < count($this->showheaders); $i++) {
233
		    $val = $this->showheaders[$i];
233
		    $val = $this->showheaders[$i];
234
		    $headers_replace .= $headers;
234
		    $headers_replace .= $headers;
235
		    $hnpos = strpos(strtolower($headers_replace), '<ezmlm-header-name>');
235
		    $hnpos = strpos(strtolower($headers_replace), '<ezmlm-header-name>');
236
		    $headers_replace = substr_replace($headers_replace, $this->header_en_francais[$val], $hnpos, 19);
236
		    $headers_replace = substr_replace($headers_replace, $this->header_en_francais[$val], $hnpos, 19);
237
		    $hvpos = strpos(strtolower($headers_replace), '<ezmlm-header-value');
237
		    $hvpos = strpos(strtolower($headers_replace), '<ezmlm-header-value');
238
            $headers_replace = $this->decode_iso ($headers_replace) ;
238
            $headers_replace = $this->decode_iso ($headers_replace) ;
239
            switch ($val) {
239
            switch ($val) {
240
            	case 'date':
240
            	case 'date':
241
            	$headers_replace = substr_replace($headers_replace, $this->date_francaise($mailDecode->headers[strtolower($val)]), $hvpos, 20);
241
            	$headers_replace = substr_replace($headers_replace, $this->date_francaise($mailDecode->headers[strtolower($val)]), $hvpos, 20);
242
            	break;
242
            	break;
243
            	case 'from':
243
            	case 'from':
244
            	if ($mailDecode->headers[strtolower($val)] == '') $from = $mailDecode->headers['return-path'] ;
244
            	if ($mailDecode->headers[strtolower($val)] == '') $from = $mailDecode->headers['return-path'] ;
245
            		else $from = $mailDecode->headers['from'];
245
            		else $from = $mailDecode->headers['from'];
246
            	$headers_replace = substr_replace($headers_replace, $this->protect_email($this->decode_iso($from)), $hvpos, 20);
246
            	$headers_replace = substr_replace($headers_replace, $this->protect_email($this->decode_iso($from)), $hvpos, 20);
247
            	//$headers_replace = htmlspecialchars($headers_replace);
247
            	//$headers_replace = htmlspecialchars($headers_replace);
248
            	break;
248
            	break;
249
            	default:
249
            	default:
250
            	$headers_replace = substr_replace($headers_replace, $this->protect_email($this->decode_iso($mailDecode->headers[strtolower($val)])), $hvpos, 20);
250
            	$headers_replace = substr_replace($headers_replace, $this->protect_email($this->decode_iso($mailDecode->headers[strtolower($val)])), $hvpos, 20);
251
            }
251
            }
252
		}
252
		}
253
        return substr_replace($this->msgtmpl_entete, $headers_replace, $startpos, (($endpos + 16) - $startpos));
253
        return substr_replace($this->msgtmpl_entete, $headers_replace, $startpos, (($endpos + 16) - $startpos));
254
    }
254
    }
255
    
255
    
256
    
256
    
257
	function parse_template(&$mailDecode, $numero_mail, $numero_mois, $num_part = '') {
257
	function parse_template(&$mailDecode, $numero_mail, $numero_mois, $num_part = '') {
258
        static $profondeur = array();
258
        static $profondeur = array();
259
        array_push ($profondeur, $num_part) ;
259
        array_push ($profondeur, $num_part) ;
260
        $corps = '' ;
260
        $corps = '' ;
261
        
261
        
262
		if ($mailDecode->ctype_primary == 'multipart') {
262
		if ($mailDecode->ctype_primary == 'multipart') {
263
            include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;
263
            include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;
264
			for ($i = 0; $i < count($mailDecode->parts); $i++) {
264
			for ($i = 0; $i < count($mailDecode->parts); $i++) {
265
                switch ($mailDecode->parts[$i]->ctype_secondary) {
265
                switch ($mailDecode->parts[$i]->ctype_secondary) {
266
                    case 'plain' : 
266
                    case 'plain' : 
267
                    if ($mailDecode->parts[$i]->headers['content-transfer-encoding'] == '8bit') {
267
                    if ($mailDecode->parts[$i]->headers['content-transfer-encoding'] == '8bit') {
268
                    	$corps .= $this->_cte_8bit($mailDecode->parts[$i]->body);
268
                    	$corps .= $this->_cte_8bit($mailDecode->parts[$i]->body);
269
                    }
269
                    }
270
                    break;
270
                    break;
271
                    case 'html' : $corps .= $mailDecode->parts[$i]->body ;
271
                    case 'html' : $corps .= $mailDecode->parts[$i]->body ;
272
                    break ;
272
                    break ;
273
                    case 'mixed' : 
273
                    case 'mixed' : 
274
                    case 'rfc822' :
274
                    case 'rfc822' :
275
                    case 'alternative' :
275
                    case 'alternative' :
276
                    case 'appledouble' :
276
                    case 'appledouble' :
277
                        $this->parse_template($mailDecode->parts[$i], $numero_mail, $numero_mois, $i) ;
277
                        $this->parse_template($mailDecode->parts[$i], $numero_mail, $numero_mois, $i) ;
278
                    break ;
278
                    break ;
279
                    case 'applefile' : continue ;
279
                    case 'applefile' : continue ;
280
                    break ;
280
                    break ;
281
                    default : 
281
                    default : 
282
                    
282
                    
283
                    if ($mailDecode->parts[$i]->ctype_secondary == 'octet-stream') {
283
                    if ($mailDecode->parts[$i]->ctype_secondary == 'octet-stream') {
284
                        $nom_piece_jointe = $mailDecode->parts[$i]->ctype_parameters['name'] ;
284
                        $nom_piece_jointe = $mailDecode->parts[$i]->ctype_parameters['name'] ;
285
                        $tab = explode ('.', $nom_piece_jointe) ;
285
                        $tab = explode ('.', $nom_piece_jointe) ;
286
                        $extension = $tab[count ($tab) - 1] ;
286
                        $extension = $tab[count ($tab) - 1] ;
287
                        $mimeType = type_fichier_mime::factory($extension, $GLOBALS['projet_db']);
287
                        $mimeType = type_fichier_mime::factory($extension, $GLOBALS['projet_db']);
288
                        $mimeType->setCheminIcone(PROJET_CHEMIN_ICONES) ;
288
                        $mimeType->setCheminIcone(PROJET_CHEMIN_ICONES) ;
289
                    } else {
289
                    } else {
290
                        $nom_piece_jointe = isset ($mailDecode->parts[$i]->d_parameters['filename']) ? 
290
                        $nom_piece_jointe = isset ($mailDecode->parts[$i]->d_parameters['filename']) ? 
291
                                            $mailDecode->parts[$i]->d_parameters['filename'] : $mailDecode->parts[$i]->ctype_parameters['name'] ;
291
                                            $mailDecode->parts[$i]->d_parameters['filename'] : $mailDecode->parts[$i]->ctype_parameters['name'] ;
292
                        $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->parts[$i]->ctype_primary.'/'.
292
                        $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->parts[$i]->ctype_primary.'/'.
293
                                            $mailDecode->parts[$i]->ctype_secondary, PROJET_CHEMIN_ICONES) ;
293
                                            $mailDecode->parts[$i]->ctype_secondary, PROJET_CHEMIN_ICONES) ;
294
                    }
294
                    }
295
                    
295
                    
296
                    $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'synchroliste/fichier_attache.php?nom_liste='.$this->listname.
296
                    $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'synchroliste/fichier_attache.php?nom_liste='.$this->listname.
297
                                    '&actionargs[]='.$numero_mois.
297
                                    '&actionargs[]='.$numero_mois.
298
                                    '&actionargs[]='.$numero_mail;
298
                                    '&actionargs[]='.$numero_mail;
299
                                    
299
                                    
300
                    if (count ($profondeur) > 0) {
300
                    if (count ($profondeur) > 0) {
301
                        array_shift($profondeur) ;
301
                        array_shift($profondeur) ;
302
                        for ($j= 0; $j < count ($profondeur); $j++) $corps .= '&actionargs[]='.$profondeur[$j];
302
                        for ($j= 0; $j < count ($profondeur); $j++) $corps .= '&actionargs[]='.$profondeur[$j];
303
                    }
303
                    }
304
                    $corps .= '&actionargs[]='.$i ;
304
                    $corps .= '&actionargs[]='.$i ;
305
                    $corps .= '">'.'<img src="'.$mimeType->getCheminIcone().'" alt="'.$nom_piece_jointe.'" />&nbsp;' ;
305
                    $corps .= '">'.'<img src="'.$mimeType->getCheminIcone().'" alt="'.$nom_piece_jointe.'" />&nbsp;' ;
306
                    $corps .= $nom_piece_jointe;
306
                    $corps .= $nom_piece_jointe;
307
                    $corps .= '</a><br />' ;
307
                    $corps .= '</a><br />' ;
308
                    break ;
308
                    break ;
309
                }
309
                }
310
            }
310
            }
311
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,TRUE), $this->msgtmpl);
311
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,TRUE), $this->msgtmpl);
312
            
312
            
313
		} else if ($mailDecode->ctype_primary == 'message') {
313
		} else if ($mailDecode->ctype_primary == 'message') {
314
            
314
            
315
            $this->message_rendu .= "\n".'<div class="message">'.$this->parse_entete_mail($mailDecode->parts[0]);
315
            $this->message_rendu .= "\n".'<div class="message">'.$this->parse_entete_mail($mailDecode->parts[0]);
316
            $corps .= $this->parse_template($mailDecode->parts[0], $numero_mail, $numero_mois, 0) ;
316
            $corps .= $this->parse_template($mailDecode->parts[0], $numero_mail, $numero_mois, 0) ;
317
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl).'</div>';
317
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl).'</div>';
318
            
318
            
319
        } else if ($mailDecode->ctype_primary == 'application' || $mailDecode->ctype_primary == 'image'){
319
        } else if ($mailDecode->ctype_primary == 'application' || $mailDecode->ctype_primary == 'image'){
320
            if ($mailDecode->ctype_secondary == 'applefile') return ;
320
            if ($mailDecode->ctype_secondary == 'applefile') return ;
321
            $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->ctype_primary.'/'.$mailDecode->ctype_secondary,PROJET_CHEMIN_ICONES) ;
321
            $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->ctype_primary.'/'.$mailDecode->ctype_secondary,PROJET_CHEMIN_ICONES) ;
322
            
322
            
323
            if ($mimeType->getIdType() != 12) {
323
            if ($mimeType->getIdType() != 12) {
324
                $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'synchroliste/fichier_attache.php?nom_liste='.$this->listname.'&actionargs[]='.
324
                $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'synchroliste/fichier_attache.php?nom_liste='.$this->listname.'&actionargs[]='.
325
                                    $numero_mois.'&actionargs[]='.
325
                                    $numero_mois.'&actionargs[]='.
326
                                    $numero_mail.'&actionargs[]='.$i.'">'.
326
                                    $numero_mail.'&actionargs[]='.$i.'">'.
327
                                    '<img src="'.$mimeType->getCheminIcone().'" alt="'.$mailDecode->ctype_parameters['name'].'" />&nbsp;' ;
327
                                    '<img src="'.$mimeType->getCheminIcone().'" alt="'.$mailDecode->ctype_parameters['name'].'" />&nbsp;' ;
328
                $corps .= $mailDecode->ctype_parameters['name'].'</a><br />' ;
328
                $corps .= $mailDecode->ctype_parameters['name'].'</a><br />' ;
329
                
329
                
330
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl);
330
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl);
331
            }
331
            }
332
        } else {
332
        } else {
333
			if (preg_match('/html/i', $mailDecode->ctype_secondary)) {
333
			if (preg_match('/html/i', $mailDecode->ctype_secondary)) {
334
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($mailDecode->body,TRUE), $this->msgtmpl);
334
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($mailDecode->body,TRUE), $this->msgtmpl);
335
            } else {
335
            } else {
336
                if (isset ($mailDecode->ctype_parameters['charset']) && $mailDecode->ctype_parameters['charset'] == 'UTF-8') {
336
                if (isset ($mailDecode->ctype_parameters['charset']) && $mailDecode->ctype_parameters['charset'] == 'UTF-8') {
337
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . utf8_decode($this->cleanup_body($mailDecode->body,TRUE)) . '</pre>', $this->msgtmpl);
337
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . utf8_decode($this->cleanup_body($mailDecode->body,TRUE)) . '</pre>', $this->msgtmpl);
338
                } else {
338
                } else {
339
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . $this->cleanup_body($mailDecode->body,TRUE) . '</pre>', $this->msgtmpl);
339
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . $this->cleanup_body($mailDecode->body,TRUE) . '</pre>', $this->msgtmpl);
340
                }
340
                }
341
            }
341
            }
342
		}
342
		}
343
	}	
343
	}	
344
 
344
 
345
	function ezmlm_msgdisplay() {
345
	function ezmlm_msgdisplay() {
346
		$this->ezmlm_php();
346
		$this->ezmlm_php();
347
		if (($this->msgtemplate != "") and (is_file($this->msgtemplate))) {
347
		if (($this->msgtemplate != "") and (is_file($this->msgtemplate))) {
348
			$fd = fopen($this->msgtemplate, "r");
348
			$fd = fopen($this->msgtemplate, "r");
349
			while (!feof($fd)) { $this->msgtmpl .= fgets($fd,4096); }
349
			while (!feof($fd)) { $this->msgtmpl .= fgets($fd,4096); }
350
			fclose($fd);
350
			fclose($fd);
351
		} else {
351
		} else {
352
			$this->msgtmpl = '<pre>
352
			$this->msgtmpl = '<pre>
353
<ezmlm-body>
353
<ezmlm-body>
354
</pre>
354
</pre>
355
        ';
355
        ';
356
		}
356
		}
357
        $this->msgtmpl_entete = '<dl><ezmlm-headers>
357
        $this->msgtmpl_entete = '<dl><ezmlm-headers>
358
<dt><ezmlm-header-name> :</dt>
358
<dt><ezmlm-header-name> :</dt>
359
<dd><ezmlm-header-value></dd>
359
<dd><ezmlm-header-value></dd>
360
</ezmlm-headers>
360
</ezmlm-headers>
361
</dl>' ;
361
</dl>' ;
362
	}
362
	}
363
 
363
 
364
}
364
}