Subversion Repositories Applications.projet

Rev

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

Rev Author Line No. Line
2 ddelon 1
<?php
106 alexandre_ 2
// $Id: ezmlm-msgdisplay.php,v 1.3 2006-04-19 13:50:04 alexandre_tb Exp $
2 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
20
 
21
	function display($msgfile) {
22
        if (!is_file($msgfile)) {
23
			if (is_file($this->listdir . "/" . $msgfile)) { $msgfile = $this->listdir . "/" . $msgfile; }
24
			else if (is_file($this->listdir . "/archive/" . $msgfile)) { $msgfile = $this->listdir . "/archive/" . $msgfile; }
25
			else { return FALSE; }
26
		}
27
        $message = file_get_contents($msgfile) ;
28
        $mimeDecode = new Mail_mimeDecode($message) ;
29
        $mailDecode = $mimeDecode->decode(array('decode_bodies' => 'true', 'include_bodies' => 'true')) ;
30
 
31
        // $msg->msgfile contient le chemin du fichier du mail en partant de la racine
32
        // Le point d'exclamation est le délimiteur de l'expression régulière
33
		$relfile = preg_replace('!' . $this->listdir . '!', '', $msgfile);
34
 
35
		$a1 = preg_replace('!/archive/(.*)/.*$!', '\1', $relfile);  // $a1 contient le nom du répertoire
36
		$a2 = preg_replace('!/archive/.*/(.*)$!', '\1', $relfile);  // $a2 contient le nom du fichier
37
		if (isset($mailDecode->headers['date'])) $msgtime = strtotime(preg_replace ('/CEST/', '', $mailDecode->headers['date']));
38
        $threadidx = date("Ym", $msgtime);
39
        if ($a2 <= 10) $numero_precedent = '0'.($a2 - 1) ; else $numero_precedent = ($a2 - 1) ;
40
        if ($a2 < 9) $numero_suivant = '0'.($a2 + 1) ; else $numero_suivant =  ($a2 + 1);
41
        // On teste si le message suivant existe
42
        $decoupe = explode ('/', $msgfile) ;
43
 
44
        // Les nom de fichiers sont du format :
45
        // archive/0/01
46
        // archive/0/02 ... 0/99 archive/1/01 ...
47
 
48
        $nom_fichier = $decoupe[count($decoupe)-1] ;
49
        $nom_repertoire = $decoupe[count($decoupe)-2] ;
50
        $repertoire_suivant = $nom_repertoire ; $repertoire_precedent = $nom_repertoire ;
51
        if ($nom_fichier > 8) {
52
            $fichier_suivant = $nom_fichier + 1 ;
53
            if ($nom_fichier == 99) {
54
                $fichier_suivant = '01' ;
55
                $repertoire_suivant = $nom_repertoire + 1 ;
56
            }
57
        } else {
58
            $fichier_suivant = '0'.($nom_fichier + 1) ;
59
        }
60
        if ($nom_fichier > 10) {
61
            $fichier_precedent = $nom_fichier - 1 ;
62
        } else {
63
            if ($nom_fichier == '01') {
64
                $fichier_precedent = '99' ;
65
                $repertoire_precedent = $nom_repertoire - 1 ;
66
            } else {
67
                $fichier_precedent = '0'.($nom_fichier - 1) ;
68
            }
69
        }
70
 
71
        if (is_file($this->listdir.'/archive/'.$repertoire_precedent.'/'.$fichier_precedent)) {
72
            print "[" . $this->makelink("action=show_msg&actionargs[]=$a1&actionargs[]=" . $numero_precedent, ' '.PROJET_PRECEDENT.' ') . "] ";
73
        } else {
74
            print '['.PROJET_PRECEDENT.']' ;
75
        }
76
        if (is_file($this->listdir.'/archive/'.$repertoire_suivant.'/'.$fichier_suivant)) {
77
            print "[" . $this->makelink("action=show_msg&actionargs[]=$a1&actionargs[]=" . $numero_suivant, ' '.PROJET_SUIVANT.' ') . "] ";
78
        } else {
79
            print '['.PROJET_SUIVANT.']' ;
80
        }
81
        // on crée un lien vers la thread avec une ancre vers le message
82
        $parser = new ezmlm_parser();
83
        $parser->listdir = $this->listdir ;
84
        $recent = $parser->recent_msgs(1);
85
        $actionargs = preg_split("/\//", $recent[0]->msgfile);
86
		print "[" . $this->makelink('action=show_msg&actionargs[]=' . $actionargs[(count($actionargs) - 2)] .
87
                                '&actionargs[]=' .  $actionargs[(count($actionargs) - 1)] , ' '.PROJET_DERNIER_MESSAGE.' ') . '] ';
88
        if ($this->_auth->getAuth()) {
89
            print '['.$this->makelink('action=repondre&actionargs[]='.$a1.'&actionargs[]='.$a2, PROJET_REPONDRE).'] ';
90
        }
91
		print '<br />'."\n";
92
        print '<div class="message">' ;
93
        print $this->parse_entete_mail($mailDecode) ;
94
		$this->parse_template($mailDecode, $a2, $a1);
95
        print $this->message_rendu;
96
        print '</div>' ;
97
	}
98
 
99
    /**
100
    *   analyse l'entete d'un mail pour en extraire les entêtes
101
    *   to, from, subject, date
102
    *   met à jour la variable $this->msgtmpl
103
    *
104
    */
105
 
106
    function parse_entete_mail (&$mailDecode) {
107
        $startpos = strpos(strtolower($this->msgtmpl_entete), '<ezmlm-headers>');
108
		$endpos = strpos(strtolower($this->msgtmpl_entete), '</ezmlm-headers>');
109
		$headers = substr($this->msgtmpl_entete,$startpos + 15,($endpos - $startpos - 15));
110
        $headers_replace = '' ;
111
		for ($i = 0; $i < count($this->showheaders); $i++) {
112
			$val = $this->showheaders[$i];
113
			$headers_replace .= $headers;
114
			$hnpos = strpos(strtolower($headers_replace), '<ezmlm-header-name>');
115
			$headers_replace = substr_replace($headers_replace, $this->header_en_francais[$val], $hnpos, 19);
116
			$hvpos = strpos(strtolower($headers_replace), '<ezmlm-header-value');
117
            if ($val == 'date') {
118
                $headers_replace = substr_replace($headers_replace, $this->date_francaise($mailDecode->headers[strtolower($val)]), $hvpos, 20);
119
            } else {
120
                $headers_replace = substr_replace($headers_replace, $this->protect_email($mailDecode->headers[strtolower($val)]), $hvpos, 20);
121
            }
122
            $headers_replace = $this->decode_iso ($headers_replace) ;
123
		}
124
 
125
		return substr_replace($this->msgtmpl_entete, $headers_replace, $startpos, (($endpos + 16) - $startpos));
126
    }
127
 
128
 
129
	function parse_template(&$mailDecode, $numero_mail, $numero_mois, $num_part = '') {
130
        static $profondeur = array();
131
        array_push ($profondeur, $num_part) ;
132
        $corps = '' ;
133
 
134
		if ($mailDecode->ctype_primary == 'multipart') {
135
            include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;
136
			for ($i = 0; $i < count($mailDecode->parts); $i++) {
137
                switch ($mailDecode->parts[$i]->ctype_secondary) {
138
                    case 'plain' :
139
                    case 'html' : $corps .= $mailDecode->parts[$i]->body ;
140
                    break ;
141
                    case 'mixed' :
142
                    case 'rfc822' :
143
                    case 'alternative' :
144
                    case 'appledouble' :
145
                        $this->parse_template($mailDecode->parts[$i], $numero_mail, $numero_mois, $i) ;
146
                    break ;
147
                    case 'applefile' : continue ;
148
                    break ;
149
                    default :
150
 
151
                    if ($mailDecode->parts[$i]->ctype_secondary == 'octet-stream') {
152
                        $nom_piece_jointe = $mailDecode->parts[$i]->ctype_parameters['name'] ;
153
                        $tab = explode ('.', $nom_piece_jointe) ;
154
                        $extension = $tab[count ($tab) - 1] ;
155
                        $mimeType = type_fichier_mime::factory($extension, $GLOBALS['projet_db']);
156
                        $mimeType->setCheminIcone(PROJET_CHEMIN_ICONES) ;
157
                    } else {
158
                        $nom_piece_jointe = isset ($mailDecode->parts[$i]->d_parameters['filename']) ?
159
                                            $mailDecode->parts[$i]->d_parameters['filename'] : $mailDecode->parts[$i]->ctype_parameters['name'] ;
160
                        $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->parts[$i]->ctype_primary.'/'.
161
                                            $mailDecode->parts[$i]->ctype_secondary, PROJET_CHEMIN_ICONES) ;
162
                    }
163
 
106 alexandre_ 164
                    $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'fichier_attache.php?nom_liste='.$this->listname.
2 ddelon 165
                                    '&actionargs[]='.$numero_mois.
166
                                    '&actionargs[]='.$numero_mail;
167
 
168
                    if (count ($profondeur) > 0) {
169
                        array_shift($profondeur) ;
170
                        for ($j= 0; $j < count ($profondeur); $j++) $corps .= '&actionargs[]='.$profondeur[$j];
171
                    }
172
                    $corps .= '&actionargs[]='.$i ;
173
                    $corps .= '">'.'<img src="'.$mimeType->getCheminIcone().'" alt="'.$nom_piece_jointe.'" />&nbsp;' ;
174
                    $corps .= $nom_piece_jointe;
175
                    $corps .= '</a><br />' ;
176
                    break ;
177
                }
178
            }
179
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,TRUE), $this->msgtmpl);
180
 
181
		} else if ($mailDecode->ctype_primary == 'message') {
182
 
183
            $this->message_rendu .= "\n".'<div class="message">'.$this->parse_entete_mail($mailDecode->parts[0]);
184
            $corps .= $this->parse_template($mailDecode->parts[0], $numero_mail, $numero_mois, 0) ;
185
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl).'</div>';
186
 
187
        } else if ($mailDecode->ctype_primary == 'application' || $mailDecode->ctype_primary == 'image'){
188
            if ($mailDecode->ctype_secondary == 'applefile') return ;
189
            $mimeType = new type_fichier_mime($GLOBALS['projet_db'], $mailDecode->ctype_primary.'/'.$mailDecode->ctype_secondary,PROJET_CHEMIN_ICONES) ;
190
 
191
            if ($mimeType->getIdType() != 12) {
106 alexandre_ 192
                $corps .= '<a href="'.PROJET_CHEMIN_APPLI.'fichier_attache.php?nom_liste='.$this->listname.'&actionargs[]='.
2 ddelon 193
                                    $numero_mois.'&actionargs[]='.
194
                                    $numero_mail.'&actionargs[]='.$i.'">'.
195
                                    '<img src="'.$mimeType->getCheminIcone().'" alt="'.$mailDecode->ctype_parameters['name'].'" />&nbsp;' ;
196
                $corps .= $mailDecode->ctype_parameters['name'].'</a><br />' ;
197
 
198
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl);
199
            }
200
        } else {
201
			if (preg_match('/html/i', $mailDecode->ctype_secondary)) {
202
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($mailDecode->body,TRUE), $this->msgtmpl);
203
            } else {
204
                if (isset ($mailDecode->ctype_parameters['charset']) && $mailDecode->ctype_parameters['charset'] == 'UTF-8') {
205
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . utf8_decode($this->cleanup_body($mailDecode->body,TRUE)) . '</pre>', $this->msgtmpl);
206
                } else {
207
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', '<pre>' . $this->cleanup_body($mailDecode->body,TRUE) . '</pre>', $this->msgtmpl);
208
                }
209
            }
210
		}
211
	}
212
 
213
	function ezmlm_msgdisplay() {
214
		$this->ezmlm_php();
215
		if (($this->msgtemplate != "") and (is_file($this->msgtemplate))) {
216
			$fd = fopen($this->msgtemplate, "r");
217
			while (!feof($fd)) { $this->msgtmpl .= fgets($fd,4096); }
218
			fclose($fd);
219
		} else {
220
			$this->msgtmpl = '<pre>
221
<ezmlm-body>
222
</pre>
223
        ';
224
		}
225
        $this->msgtmpl_entete = '<dl><ezmlm-headers>
226
<dt><ezmlm-header-name> :</dt>
227
<dd><ezmlm-header-value></dd>
228
</ezmlm-headers>
229
</dl>' ;
230
	}
231
 
232
}