Subversion Repositories Applications.papyrus

Rev

Rev 1087 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
448 ddelon 1
<?php
1229 alexandre_ 2
// $Id: ezmlm-msgdisplay.php,v 1.3.2.1 2007-02-16 13:38:35 alexandre_tb Exp $
448 ddelon 3
//
4
// ezmlm-msgdisplay.php - ezmlm-php v2.0
5
// --------------------------------------------------------------
6
// Will parse a template (if specified) and display a message.
7
// Includes a default template.
8
// --------------------------------------------------------------
9
 
10
require_once("ezmlm.php");
11
require_once("Mail/mimeDecode.php") ;
12
 
13
class ezmlm_msgdisplay extends ezmlm_php {
14
	// our template
15
	var $msgtmpl;
16
    var $message_rendu ;
17
    var $_auth ;
18
	// display: parses a message (using ezmlm_parser) and displays it
19
	// using a template
1229 alexandre_ 20
    var $msgfile;
448 ddelon 21
 
1229 alexandre_ 22
    function display($msgfile) {
448 ddelon 23
        if (!is_file($msgfile)) {
1229 alexandre_ 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; }
26
		else { return FALSE; }
27
	    }
28
	$this->msgfile = $msgfile ;
448 ddelon 29
        $message = file_get_contents($msgfile) ;
1229 alexandre_ 30
	// En cours de codage
31
	// La fonction display retourne tout simplement le source du mail
32
	// Il n'y a plus d'analyse à ce niveau
33
 
34
	return $message;
448 ddelon 35
        $mimeDecode = new Mail_mimeDecode($message) ;
36
        $mailDecode = $mimeDecode->decode(array('decode_bodies' => 'true', 'include_bodies' => 'true')) ;
37
 
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
40
		$relfile = preg_replace('!' . $this->listdir . '!', '', $msgfile);
41
 
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
44
		if (isset($mailDecode->headers['date'])) $msgtime = strtotime(preg_replace ('/CEST/', '', $mailDecode->headers['date']));
45
        $threadidx = date("Ym", $msgtime);
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);
48
        // On teste si le message suivant existe
49
        $decoupe = explode ('/', $msgfile) ;
50
 
51
        // Les nom de fichiers sont du format :
52
        // archive/0/01
53
        // archive/0/02 ... 0/99 archive/1/01 ...
54
 
55
        $nom_fichier = $decoupe[count($decoupe)-1] ;
56
        $nom_repertoire = $decoupe[count($decoupe)-2] ;
57
        $repertoire_suivant = $nom_repertoire ; $repertoire_precedent = $nom_repertoire ;
58
        if ($nom_fichier > 8) {
59
            $fichier_suivant = $nom_fichier + 1 ;
60
            if ($nom_fichier == 99) {
61
                $fichier_suivant = '01' ;
62
                $repertoire_suivant = $nom_repertoire + 1 ;
63
            }
64
        } else {
65
            $fichier_suivant = '0'.($nom_fichier + 1) ;
66
        }
67
        if ($nom_fichier > 10) {
68
            $fichier_precedent = $nom_fichier - 1 ;
69
        } else {
70
            if ($nom_fichier == '01') {
71
                $fichier_precedent = '99' ;
72
                $repertoire_precedent = $nom_repertoire - 1 ;
73
            } else {
74
                $fichier_precedent = '0'.($nom_fichier - 1) ;
75
            }
76
        }
77
        print $this->parse_entete_mail($mailDecode) ;
78
		$this->parse_template($mailDecode, $a2, $a1);
79
        print $this->message_rendu;
1229 alexandre_ 80
        //print '</div>' ;
448 ddelon 81
	}
82
 
83
    /**
1229 alexandre_ 84
     * Renvoie les infos des messages suivants
85
     *
86
     *
87
    */
88
    function getInfoSuivant() {
89
	$relfile = preg_replace('!' . $this->listdir . '!', '', $this->msgfile);
90
 	$a1 = preg_replace('!/archive/(.*)/.*$!', '\1', $relfile);  // $a1 contient le nom du répertoire
91
	$a2 = preg_replace('!/archive/.*/(.*)$!', '\1', $relfile);  // $a2 contient le nom du fichier
92
 
93
	if ($a2 <= 10) $numero_precedent = '0'.($a2 - 1) ; else $numero_precedent = ($a2 - 1) ;
94
        if ($a2 < 9) $numero_suivant = '0'.($a2 + 1) ; else $numero_suivant =  ($a2 + 1);
95
        // On teste si le message suivant existe
96
        $decoupe = explode ('/', $this->msgfile) ;
97
 
98
        // Les nom de fichiers sont du format :
99
        // archive/0/01
100
        // archive/0/02 ... 0/99 archive/1/01 ...
101
 
102
        $nom_fichier = $decoupe[count($decoupe)-1] ;
103
        $nom_repertoire = $decoupe[count($decoupe)-2] ;
104
        $repertoire_suivant = $nom_repertoire ; $repertoire_precedent = $nom_repertoire ;
105
        if ($nom_fichier > 8) {
106
            $fichier_suivant = $nom_fichier + 1 ;
107
            if ($nom_fichier == 99) {
108
                $fichier_suivant = '01' ;
109
                $repertoire_suivant = $nom_repertoire + 1 ;
110
            }
111
        } else {
112
            $fichier_suivant = '0'.($nom_fichier + 1) ;
113
        }
114
        if ($nom_fichier > 10) {
115
            $fichier_precedent = $nom_fichier - 1 ;
116
        } else {
117
            if ($nom_fichier == '01') {
118
                $fichier_precedent = '99' ;
119
                $repertoire_precedent = $nom_repertoire - 1 ;
120
            } else {
121
                $fichier_precedent = '0'.($nom_fichier - 1) ;
122
            }
123
	}
124
	// On vérifie que le message suivant existe bien
125
	if (!file_exists($this->listdir.'/archive/'.$repertoire_suivant.'/'.$fichier_suivant)) {
126
	    $fichier_suivant = null ;
127
	}
128
	return array ('fichier_suivant' => $fichier_suivant,
129
		      'repertoire_suivant' => $repertoire_suivant,
130
		      'fichier_precedent' => $fichier_precedent,
131
		      'repertoire_precedent' => $repertoire_precedent);
132
    }
133
 
134
    /**
448 ddelon 135
    *   analyse l'entete d'un mail pour en extraire les entêtes
136
    *   to, from, subject, date
137
    *   met à jour la variable $this->msgtmpl
138
    *
139
    */
140
 
141
    function parse_entete_mail (&$mailDecode) {
142
        $startpos = strpos(strtolower($this->msgtmpl_entete), '<ezmlm-headers>');
1229 alexandre_ 143
        $endpos = strpos(strtolower($this->msgtmpl_entete), '</ezmlm-headers>');
144
	$headers = substr($this->msgtmpl_entete,$startpos + 15,($endpos - $startpos - 15));
448 ddelon 145
        $headers_replace = '' ;
1229 alexandre_ 146
	for ($i = 0; $i < count($this->showheaders); $i++) {
147
	    $val = $this->showheaders[$i];
148
	    $headers_replace .= $headers;
149
	    $hnpos = strpos(strtolower($headers_replace), '<ezmlm-header-name>');
150
	    $headers_replace = substr_replace($headers_replace, $this->header_en_francais[$val], $hnpos, 19);
151
	    $hvpos = strpos(strtolower($headers_replace), '<ezmlm-header-value');
152
            $headers_replace = $this->decode_iso ($headers_replace) ;
448 ddelon 153
            if ($val == 'date') {
154
                $headers_replace = substr_replace($headers_replace, $this->date_francaise($mailDecode->headers[strtolower($val)]), $hvpos, 20);
155
            } else {
1229 alexandre_ 156
                $headers_replace = substr_replace($headers_replace, $this->protect_email($this->decode_iso($mailDecode->headers[strtolower($val)])), $hvpos, 20);
448 ddelon 157
            }
1229 alexandre_ 158
	}
159
        return substr_replace($this->msgtmpl_entete, $headers_replace, $startpos, (($endpos + 16) - $startpos));
448 ddelon 160
    }
161
 
162
 
163
	function parse_template(&$mailDecode, $numero_mail, $numero_mois, $num_part = '') {
164
        static $profondeur = array();
165
        array_push ($profondeur, $num_part) ;
166
        $corps = '' ;
167
 
168
		if ($mailDecode->ctype_primary == 'multipart') {
169
            include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;
170
			for ($i = 0; $i < count($mailDecode->parts); $i++) {
171
                switch ($mailDecode->parts[$i]->ctype_secondary) {
172
                    case 'plain' :
173
                    case 'html' : $corps .= $mailDecode->parts[$i]->body ;
174
                    break ;
175
                    case 'mixed' :
176
                    case 'rfc822' :
177
                    case 'alternative' :
178
                    case 'appledouble' :
179
                        $this->parse_template($mailDecode->parts[$i], $numero_mail, $numero_mois, $i) ;
180
                    break ;
181
                    case 'applefile' : continue ;
182
                    break ;
183
                    default :
184
 
185
                    if ($mailDecode->parts[$i]->ctype_secondary == 'octet-stream') {
186
                        $nom_piece_jointe = $mailDecode->parts[$i]->ctype_parameters['name'] ;
187
                        $tab = explode ('.', $nom_piece_jointe) ;
188
                        $extension = $tab[count ($tab) - 1] ;
189
                        $mimeType = type_fichier_mime::factory($extension, $GLOBALS['projet_db']);
190
                        $mimeType->setCheminIcone(PROJET_CHEMIN_ICONES) ;
191
                    } else {
192
                        $nom_piece_jointe = isset ($mailDecode->parts[$i]->d_parameters['filename']) ?
193
                                            $mailDecode->parts[$i]->d_parameters['filename'] : $mailDecode->parts[$i]->ctype_parameters['name'] ;
194
                        $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->parts[$i]->ctype_primary.'/'.
195
                                            $mailDecode->parts[$i]->ctype_secondary, PROJET_CHEMIN_ICONES) ;
196
                    }
197
 
1229 alexandre_ 198
                    $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'synchroliste/fichier_attache.php?nom_liste='.$this->listname.
448 ddelon 199
                                    '&actionargs[]='.$numero_mois.
200
                                    '&actionargs[]='.$numero_mail;
201
 
202
                    if (count ($profondeur) > 0) {
203
                        array_shift($profondeur) ;
204
                        for ($j= 0; $j < count ($profondeur); $j++) $corps .= '&actionargs[]='.$profondeur[$j];
205
                    }
206
                    $corps .= '&actionargs[]='.$i ;
207
                    $corps .= '">'.'<img src="'.$mimeType->getCheminIcone().'" alt="'.$nom_piece_jointe.'" />&nbsp;' ;
208
                    $corps .= $nom_piece_jointe;
209
                    $corps .= '</a><br />' ;
210
                    break ;
211
                }
212
            }
213
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,TRUE), $this->msgtmpl);
214
 
215
		} else if ($mailDecode->ctype_primary == 'message') {
216
 
217
            $this->message_rendu .= "\n".'<div class="message">'.$this->parse_entete_mail($mailDecode->parts[0]);
218
            $corps .= $this->parse_template($mailDecode->parts[0], $numero_mail, $numero_mois, 0) ;
219
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl).'</div>';
220
 
221
        } else if ($mailDecode->ctype_primary == 'application' || $mailDecode->ctype_primary == 'image'){
222
            if ($mailDecode->ctype_secondary == 'applefile') return ;
223
            $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->ctype_primary.'/'.$mailDecode->ctype_secondary,PROJET_CHEMIN_ICONES) ;
224
 
225
            if ($mimeType->getIdType() != 12) {
1229 alexandre_ 226
                $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'synchroliste/fichier_attache.php?nom_liste='.$this->listname.'&actionargs[]='.
448 ddelon 227
                                    $numero_mois.'&actionargs[]='.
228
                                    $numero_mail.'&actionargs[]='.$i.'">'.
229
                                    '<img src="'.$mimeType->getCheminIcone().'" alt="'.$mailDecode->ctype_parameters['name'].'" />&nbsp;' ;
230
                $corps .= $mailDecode->ctype_parameters['name'].'</a><br />' ;
231
 
232
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl);
233
            }
234
        } else {
235
			if (preg_match('/html/i', $mailDecode->ctype_secondary)) {
236
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($mailDecode->body,TRUE), $this->msgtmpl);
237
            } else {
238
                if (isset ($mailDecode->ctype_parameters['charset']) && $mailDecode->ctype_parameters['charset'] == 'UTF-8') {
239
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . utf8_decode($this->cleanup_body($mailDecode->body,TRUE)) . '</pre>', $this->msgtmpl);
240
                } else {
241
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . $this->cleanup_body($mailDecode->body,TRUE) . '</pre>', $this->msgtmpl);
242
                }
243
            }
244
		}
245
	}
246
 
247
	function ezmlm_msgdisplay() {
248
		$this->ezmlm_php();
249
		if (($this->msgtemplate != "") and (is_file($this->msgtemplate))) {
250
			$fd = fopen($this->msgtemplate, "r");
251
			while (!feof($fd)) { $this->msgtmpl .= fgets($fd,4096); }
252
			fclose($fd);
253
		} else {
254
			$this->msgtmpl = '<pre>
255
<ezmlm-body>
256
</pre>
257
        ';
258
		}
259
        $this->msgtmpl_entete = '<dl><ezmlm-headers>
260
<dt><ezmlm-header-name> :</dt>
261
<dd><ezmlm-header-value></dd>
262
</ezmlm-headers>
263
</dl>' ;
264
	}
265
 
266
}