Subversion Repositories Applications.projet

Rev

Rev 406 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 mathias 1
<?php
2
// $Id: ezmlm-repondre.php,v 1.2 2005-09-27 16:43:08 alexandre_tb Exp $
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
 
14
class ezmlm_repondre extends ezmlm_php {
15
	// our template
16
	var $msgtmpl;
17
    var $message_rendu ;
18
	// display: parses a message (using ezmlm_parser) and displays it
19
	// using a template
20
 
21
	function repondre($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
        print '<br />'."\n";
72
        $this->parse_template($mailDecode, $a2, $a1);
73
 
74
        $formulaireReponse = new HTML_formulaireMail('formulaire_reponse', 'post', str_replace('&amp;', '&', $this->forcehref).'&action=repondre&'.
75
                                                    'actionargs[]='.$a1.'&actionargs[]='.$a2.'&'.PROJET_VARIABLE_ACTION.'='.PROJET_ENVOYER_UN_MAIL_V) ;
76
        $formulaireReponse->construitFormulaire() ;
77
 
78
        $formulaireReponse->addElement ('hidden', 'messageid', $mailDecode->headers['message-id']) ;
79
        // Ajout de > au début de chaque ligne du message
80
        $tableau = explode ("\n", $this->message_rendu) ;
81
        $this->message_rendu = "> ".implode ("\n> ", $tableau) ;
82
 
83
        $formulaireReponse->setDefaults(array('mail_corps' => $this->message_rendu,
84
                                              'mail_titre' => 'Re : '.$this->decode_iso ($mailDecode->headers['subject']))) ;
85
 
86
        print $formulaireReponse->toHTML() ;
87
 
88
 
89
	}
90
 
91
 
92
	function parse_template(&$mailDecode, $numero_mail, $numero_mois, $num_part = '') {
93
        static $profondeur = array();
94
        array_push ($profondeur, $num_part) ;
95
        $corps = '' ;
96
 
97
		if ($mailDecode->ctype_primary == 'multipart') {
98
            include_once PROJET_CHEMIN_CLASSES.'type_fichier_mime.class.php' ;
99
			for ($i = 0; $i < count($mailDecode->parts); $i++) {
100
                switch ($mailDecode->parts[$i]->ctype_secondary) {
101
                    case 'plain' :
102
                    case 'html' : $corps .= $mailDecode->parts[$i]->body ;
103
                    break ;
104
                    case 'mixed' :
105
                    case 'rfc822' :
106
                    case 'alternative' :
107
                    case 'appledouble' :
108
                        $this->parse_template($mailDecode->parts[$i], $numero_mail, $numero_mois, $i) ;
109
                    break ;
110
                    case 'applefile' : continue ;
111
                    break ;
112
                    default :
113
 
114
                    if ($mailDecode->parts[$i]->ctype_secondary == 'octet-stream') {
115
                        $nom_piece_jointe = $mailDecode->parts[$i]->ctype_parameters['name'] ;
116
                        $tab = explode ('.', $nom_piece_jointe) ;
117
                        $extension = $tab[count ($tab) - 1] ;
118
                        $mimeType = type_fichier_mime::factory($extension);
119
                        $mimeType->setCheminIcone(PROJET_CHEMIN_ICONES) ;
120
                    } else {
121
                        $nom_piece_jointe = isset ($mailDecode->parts[$i]->d_parameters['filename']) ?
122
                                            $mailDecode->parts[$i]->d_parameters['filename'] : $mailDecode->parts[$i]->ctype_parameters['name'] ;
123
                        $mimeType = new type_fichier_mime( $mailDecode->parts[$i]->ctype_primary.'/'.
124
                                            $mailDecode->parts[$i]->ctype_secondary, PROJET_CHEMIN_ICONES) ;
125
                    }
126
 
127
                    $corps .= '';
128
 
129
                    if (count ($profondeur) > 0) {
130
                        array_shift($profondeur) ;
131
                        //for ($j= 0; $j < count ($profondeur); $j++) $corps .= '&actionargs[]='.$profondeur[$j];
132
                    }
133
                    /*$corps .= '&actionargs[]='.$i ;
134
                    $corps .= '">'.'<img src="'.$mimeType->getCheminIcone().'" alt="'.$nom_piece_jointe.'" />&nbsp;' ;
135
                    $corps .= $nom_piece_jointe;
136
                    $corps .= '</a><br />' ;*/
137
                    break ;
138
                }
139
            }
140
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,TRUE), $this->msgtmpl);
141
 
142
		} else if ($mailDecode->ctype_primary == 'message') {
143
 
144
            $this->message_rendu .= "\n".'<div class="message">'.$this->parse_entete_mail($mailDecode->parts[0]);
145
            $corps .= $this->parse_template($mailDecode->parts[0], $numero_mail, $numero_mois, 0) ;
146
            $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl).'</div>';
147
 
148
        } else if ($mailDecode->ctype_primary == 'application' || $mailDecode->ctype_primary == 'image'){
149
            if ($mailDecode->ctype_secondary == 'applefile') return ;
150
            $mimeType = new type_fichier_mime( $mailDecode->ctype_primary.'/'.$mailDecode->ctype_secondary,PROJET_CHEMIN_ICONES) ;
151
 
152
            if ($mimeType->getIdType() != 12) {
153
                $corps .= '' ;
154
 
155
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($corps,true), $this->msgtmpl);
156
            }
157
        } else {
158
			if (preg_match('/html/i', $mailDecode->ctype_secondary)) {
159
                $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($mailDecode->body), $this->msgtmpl);
160
            } else {
161
                if (isset ($mailDecode->ctype_parameters['charset']) && $mailDecode->ctype_parameters['charset'] == 'UTF-8') {
162
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', utf8_decode($this->cleanup_body($mailDecode->body)) , $this->msgtmpl);
163
                } else {
164
 
165
                    $this->message_rendu .= preg_replace('/<ezmlm-body>/i', $this->cleanup_body($mailDecode->body), $this->msgtmpl);
166
                }
167
            }
168
		}
169
	}
170
 
171
	function ezmlm_repondre() {
172
		$this->ezmlm_php();
173
		if (($this->msgtemplate != "") and (is_file($this->msgtemplate))) {
174
			$fd = fopen($this->msgtemplate, "r");
175
			while (!feof($fd)) { $this->msgtmpl .= fgets($fd,4096); }
176
			fclose($fd);
177
		} else {
178
			$this->msgtmpl = '<ezmlm-body>';
179
		}
180
        $this->msgtmpl_entete = '<dl><ezmlm-headers>
181
<dt><ezmlm-header-name> :</dt>
182
<dd><ezmlm-header-value></dd>
183
</ezmlm-headers>
184
</dl>' ;
185
	}
186
 
187
}