source: trunk/expressoMail1_2/inc/class.exporteml.inc.php @ 1802

Revision 1802, 20.0 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #815 - Foi modificado o método remove_accents sendo adicionada as aspas simples

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2/***************************************************************************************\
3* Export EML Format Message Mail                                                                                                                *
4* Written by Nilton Neto (Celepar) <niltonneto@celepar.pr.gov.br>                                               *
5* ------------------------------------------------------------------------------------  *
6*  This program is free software; you can redistribute it and/or modify it                              *
7*   under the terms of the GNU General Public License as published by the                               *
8*  Free Software Foundation; either version 2 of the License, or (at your                               *
9*  option) any later version.                                                                                                                   *
10\****************************************************************************************/
11// BEGIN CLASS
12class ExportEml
13{
14        var $msg;
15        var $folder;
16        var $mbox_stream;
17       
18        function connectImap(){
19       
20                $username = $_SESSION['phpgw_info']['expressomail']['user']['userid'];
21                $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd'];
22                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer'];
23                $imap_port      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort'];
24               
25                if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes')
26                {
27                        $imap_options = '/tls/novalidate-cert';
28                }
29                else
30                {
31                        $imap_options = '/notls/novalidate-cert';
32                }
33                $this->mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$this->folder, $username, $password);
34        }
35       
36        //export message to EML Format
37        function parseEml($header, $body)       
38        {               
39                $sEmailHeader = $header;
40                $sEmailBody = $body;
41                $sEMail = $sEmailHeader . "\r\n\r\n" . $sEmailBody;             
42                return $sEMail;
43        }
44       
45        // create EML File.
46        // Funcao alterada para tratar a exportacao
47        // de mensagens arquivadas localmente.
48        // Rommel Cysne (rommel.cysne@serpro.gov.br)
49        // em 17/12/2008.
50        function createFileEml($sEMLData, $tempDir, $id, $subject=false, $i=false)
51    {
52        if($id)
53        {
54            $header    = imap_headerinfo($this->mbox_stream, imap_msgno($this->mbox_stream, $id), 80, 255);
55            $subject = $this->decode_subject($header->fetchsubject);
56           
57            if (strlen($subject) > 60)
58                $subject = substr($subject, 0, 59);
59 
60                        //$subject = ereg_replace('/', '\'', $subject);
61                        $from = "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ";
62                        $to =   "aaaaaeeeeiiiiooooouuuuc__________________________________________AAAAAEEEEIIIIOOOOOUUUUC";
63                        $subject = strtr($subject,$from,$to);
64            $file =    $subject."_".$id.".eml";
65                } else{
66                        // Se mensagem for arquivada localmente, $subject (assunto da mensagem)
67                        // sera passado para compor o nome do arquivo .eml;
68
69                        if($subject && $i){
70                                $from = "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ";
71                                $to =   "aaaaaeeeeiiiiooooouuuuc__________________________________________AAAAAEEEEIIIIOOOOOUUUUC";
72                                $subject = strtr($subject,$from,$to);
73                                //$subject = ereg_replace(':', '_', $subject);
74                                //$subject = ereg_replace('/', '_', $subject);
75                                $file = $subject."_".$i.".eml";
76                        } else{
77                                $file = "email_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".eml";
78                }   
79        }
80       
81        $f = fopen($tempDir.'/'.$file,"w");
82        if(!$f)
83            return False;
84       
85        fputs($f,$sEMLData);
86        fclose($f);
87       
88        return $file;
89    }
90
91        function createFileZip($files, $tempDir){               
92                $tmp_zip_filename = "email_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".zip";
93                $command = "cd " . escapeshellarg($tempDir) . " && nice zip -m9 " . escapeshellarg($tmp_zip_filename) . " " .  escapeshellcmd($files);
94                if(!exec($command)) {
95                        $command = "cd " .  escapeshellarg($tempDir) . " && rm ".escapeshellcmd($files)." ". escapeshellarg($tmp_zip_filename);
96                        exec($command);
97                        return null;
98                }
99               
100                return $tmp_zip_filename;
101                               
102        }
103
104        function export_all($params){
105               
106                $this->folder = $params['folder'];
107                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
108                $fileNames = "";
109                $tempDir = ini_get("session.save_path");
110                $this->connectImap();
111               
112                $msgs = imap_search($this->mbox_stream,"ALL",SE_UID);
113                if($msgs){
114                        foreach($msgs as $nMsgs){
115                                $header         = $this-> getHeader($nMsgs);                                                                   
116                                $body           = $this-> getBody($nMsgs);                     
117                                $sEMLData       = $this -> parseEml($header, $body);
118                                $fileName       = $this -> CreateFileEml($sEMLData, $tempDir,$nMsgs);
119                                if(!$fileName)  {
120                                        $error = True;                                 
121                                        break;
122                                }
123                                else
124                                        $fileNames .= "\"".$fileName."\" ";                     
125                               
126                        }
127                       
128                        imap_close($this->mbox_stream);
129                       
130                        $nameFileZip = 'False';                 
131                        if($fileNames && !$error) {                     
132                                $nameFileZip = $this -> createFileZip($fileNames, $tempDir);
133                                if($nameFileZip)                       
134                                        $file = $tempDir.'/'.$nameFileZip;
135                                else {
136                                        $file = false;
137                                }                                                               
138                        }
139                        else
140                                $file = false;
141                }else{
142                        $file["empty_folder"] = true;
143                }
144                return $file;
145               
146        }
147
148        // Funcao alterada para tratar a exportacao
149        // de mensagens arquivadas localmente.
150        // Rommel Cysne (rommel.cysne@serpro.gov.br)
151        // em 17/12/2008.
152        function makeAll($params) {
153                // Exportacao de mensagens arquivadas localmente
154                if($params['l_msg'] == "t"){
155                // Recebe todos os subjects e bodies das mensagens locais selecionadas para exportacao
156                // e gera arrays com os conteudos separados;
157                $array_mesgs = explode('@@',$params['mesgs']);
158                $array_subjects = explode('@@',$params['subjects']);
159            $array_ids = explode(',', $params['msgs_to_export']);
160            $tempDir = ini_get("session.save_path");
161                        // Para cada mensagem selecionada sera gerado um arquivo .eml cujo titulo sera o assunto (subject) da mesma;
162                        include_once("class.imap_functions.inc.php");
163                        $imapf = new imap_functions();
164                foreach($array_ids as $i=>$id) {
165                                $sEMLData=$imapf->treat_base64_from_post($array_mesgs[$i]);
166                                $fileName=$this->CreateFileEml($sEMLData, $tempDir,'',$array_subjects[$i],$i);
167                                if(!$fileName){
168                                        $error = True;
169                                        break;
170                                } else{
171                                        $fileNames .= "\"".$fileName."\" ";
172                                }
173                        }
174                        $nameFileZip = 'False';
175                        if($fileNames && !$error) {
176                                $nameFileZip = $this -> createFileZip($fileNames, $tempDir);
177                                if($nameFileZip){
178                                        $file = $tempDir.'/'.$nameFileZip;
179                                } else{
180                                        $file = false;
181                                }
182
183                        } else{
184                                $file = false;
185                        }
186
187            return $file;
188
189                // Exportacao de mensagens da caixa de entrada (imap) - processo original do Expresso
190                } else{
191            $this-> folder = $params['folder'];
192            $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
193            $array_ids = explode(',', $params['msgs_to_export']);
194            $error = False;
195            $fileNames = "";
196            $tempDir = ini_get("session.save_path");
197            $this->connectImap();
198                        for($i = 0; $i < count($array_ids); $i++) {
199                        $header         = $this-> getHeader($array_ids[$i]);                                                                                   
200                        $body           = $this-> getBody($array_ids[$i]);                     
201                        $sEMLData       = $this -> parseEml($header, $body);                   
202                        $fileName       = $this -> CreateFileEml($sEMLData, $tempDir, $array_ids[$i]);
203                       
204                        if(!$fileName)  {
205                                $error = True;                                 
206                                break;
207                        }
208                        else
209                                $fileNames .= "\"".$fileName."\" ";                     
210                       
211                }
212                imap_close($this->mbox_stream);
213               
214               
215                $nameFileZip = 'False';                 
216                if($fileNames && !$error) {                     
217                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir);
218                        if($nameFileZip)                       
219                                $file = $tempDir.'/'.$nameFileZip;
220                        else {
221                                $file = false;
222                        }                                                               
223                }
224                else
225                        $file = false;
226                       
227                return $file;
228        }
229    }
230
231        function export_msg($params) {
232                $this-> folder = $params['folder'];
233                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
234                $id_number = $params['msgs_to_export'];
235                $tempDir = ini_get("session.save_path");
236               
237                $this->connectImap();
238                $header         = $this-> getHeader($id_number);
239                $body           = $this-> getBody($id_number);
240               
241                $file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".txt";
242                $f = fopen($tempDir.'/'.$file,"w");
243                fputs($f,$header ."\r\n\r\n". $body);
244                fclose($f);
245               
246                imap_close($this->mbox_stream);
247                return $tempDir.'/'.$file;
248        }
249
250    function export_msg_data($id_msg,$folder) {
251                $this->folder = $folder;
252                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
253
254                $this->connectImap();
255                $header         = $this-> getHeader($id_msg);
256                $body           = $this-> getBody($id_msg);
257
258                $msg_data = $header ."\r\n\r\n". $body;
259
260                imap_close($this->mbox_stream);
261                return $msg_data;
262        }
263
264        function export_to_archive($id_msg,$folder) {
265                $this->folder = $folder;
266                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
267                $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';
268               
269                $phpheader = "<?php header('Content-Type: text/plain');
270                                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
271                                header('Pragma: public');
272                                header('Expires: 0'); // set expiration time
273                                header('Content-Disposition: attachment; filename=\"fonte_da_mensagem.txt\"');?>";
274               
275                $this->connectImap();
276                $header         = $this-> getHeader($id_msg);
277                $body           = $this-> getBody($id_msg);
278               
279                $tempSubDir = md5($_SESSION[ 'phpgw_session' ][ 'session_id' ].microtime());
280                $file = "source_".$tempSubDir.".php";
281                //$file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".php";
282                $f = fopen($tempDir.'/'.$file,"w");
283                fputs($f,$phpheader.$header ."\r\n\r\n". $body);
284                fclose($f);
285                $urlPath = 'tmpLclAtt/'.$file;
286               
287                imap_close($this->mbox_stream);
288                return $urlPath;
289        }
290
291        function remove_accents($string) {
292                /*
293                        $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç" , "?", "\"", "!", "@", "#", "$", "%", "š", "&", "*", "(", ")", "-", "=", "+", "Ž", "`", "[", "]", "{", "}", "~", "^", ",", "<", ">", ";", ":", "/", "?", "\\", "|", "¹", "²", "³", "£", "¢", "¬", "§", "ª", "º", "°", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
294                        $array2 = array("a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c" , "" , ""  , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" , "" ,  "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
295                        return str_replace( $array1, $array2, $string );
296                */
297                return strtr($string,
298                        "áàâãäéèêëíìîïóòôõöúùûüç?\"'!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ",
299                        "aaaaaeeeeiiiiooooouuuuc__________________________________________AAAAAEEEEIIIIOOOOOUUUUC");
300        }
301       
302        function get_attachments_in_array($params) {
303                $return_attachments = array();
304
305                $id_number = $params['num_msg'];               
306                $attachments =unserialize(rawurldecode($params['s_attachments']));
307               
308                $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';
309//              $tempDir = $_SERVER["DOCUMENT_ROOT"]."tmpLclAtt";
310                $tempSubDir = md5(microtime());
311                exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);
312               
313                $this-> folder = $params['folder'];
314                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
315                $this->connectImap();
316
317                include_once("class.imap_attachment.inc.php");
318
319                $imap_attachment = new imap_attachment();
320                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
321                foreach($attachments as $i => $attachment){
322                        if($i && $i == 'names')
323                                continue;
324                        $fileNameReal = $this->remove_accents($attachment['name']);
325                        $ContentType = $this->getFileType($fileNameReal);
326                        $fileName = $fileNameReal;
327                        if(strpos($ContentType,"text")!==false ||
328                                        strpos($ContentType,"image")!==false ||
329                                        strpos($ContentType,"audio")!==false)
330                                $fileName.= ".php";
331                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
332                        if(!$f)
333                                return $tempDir . '/'.$tempSubDir.'/'.$fileName;                       
334
335                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
336                        $urlPath = 'tmpLclAtt/'.$tempSubDir.'/'.$fileName;
337                       
338                        if(strpos($ContentType,"text")!==false ||
339                                        strpos($ContentType,"image")!==false ||
340                                        strpos($ContentType,"audio")!==false) {
341                                $headers = "<?php header('Content-Type: ".$ContentType."');
342                                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
343                                        header('Pragma: public');
344                                        header('Expires: 0'); // set expiration time
345                                        header('Content-Disposition: attachment; filename=\"". addslashes($fileNameReal) ."\"');\n echo ";
346                       
347                                if($attachment['encoding'] == 'base64') {
348                                        $headers.="imap_base64('".$fileContent."');?>";
349                                }
350                                else if($attachment['encoding'] == 'quoted_printable_decode') {
351                                        $headers.="quoted_printable_decode('".$fileContent."');?>";
352                                }
353                                else {
354                                        $headers.="'".$fileContent."';?>";
355                                }
356                        }
357                        else {
358                                if($attachment['encoding'] == 'base64') {
359                                        $headers=imap_base64($fileContent);
360                                }
361                                else if($attachment['encoding'] == 'quoted_printable_decode') {
362                                        $headers=quoted_printable_decode($fileContent);
363                                }
364                                else {
365                                        $headers=$fileContent;
366                                }
367                        }
368                       
369                        fputs($f,$headers);
370
371                        array_push($return_attachments,array('name' => $fileName,'url' => $urlPath,'pid' =>$attachment['pid']));
372                        fclose($f);
373                }
374                imap_close($this->mbox_stream);
375                return $return_attachments;
376        }
377       
378        private function getFileType($nameFile) {
379                $strFileType = strrev(substr(strrev(strtolower($nameFile)),0,4));
380                $ContentType = "application/octet-stream";
381                if ($strFileType == ".asf")
382                        $ContentType = "video/x-ms-asf";
383                if ($strFileType == ".avi")
384                        $ContentType = "video/avi";
385                if ($strFileType == ".doc")
386                        $ContentType = "application/msword";
387                if ($strFileType == ".zip")
388                        $ContentType = "application/zip";
389                if ($strFileType == ".xls")
390                        $ContentType = "application/vnd.ms-excel";
391                if ($strFileType == ".gif")
392                        $ContentType = "image/gif";
393                if ($strFileType == ".png")
394                        $ContentType = "image/png";
395                if ($strFileType == ".jpg" || $strFileType == "jpeg")
396                        $ContentType = "image/jpeg";
397                if ($strFileType == ".wav")
398                        $ContentType = "audio/wav";
399                if ($strFileType == ".mp3")
400                        $ContentType = "audio/mpeg3";
401                if ($strFileType == ".mpg" || $strFileType == "mpeg")
402                        $ContentType = "video/mpeg";
403                if ($strFileType == ".rtf")
404                        $ContentType = "application/rtf";
405                if ($strFileType == ".htm" || $strFileType == "html")
406                        $ContentType = "text/html";
407                if ($strFileType == ".xml")
408                        $ContentType = "text/xml";
409                if ($strFileType == ".xsl")
410                        $ContentType = "text/xsl";
411                if ($strFileType == ".css")
412                        $ContentType = "text/css";
413                if ($strFileType == ".php")
414                        $ContentType = "text/php";
415                if ($strFileType == ".asp")
416                        $ContentType = "text/asp";
417                if ($strFileType == ".pdf")
418                        $ContentType = "application/pdf";
419                if ($strFileType == ".txt")
420                        $ContentType = "text/plain";
421                if ($strFileType == ".log")
422                        $ContentType = "text/plain";
423                if ($strFileType == ".wmv")
424                        $ContentType = "video/x-ms-wmv";
425                if ($strFileType == ".sxc")
426                        $ContentType = "application/vnd.sun.xml.calc";
427                if ($strFileType == ".odt")
428                        $ContentType = "application/vnd.oasis.opendocument.text";
429                if ($strFileType == ".stc")
430                        $ContentType = "application/vnd.sun.xml.calc.template";
431                if ($strFileType == ".sxd")
432                        $ContentType = "application/vnd.sun.xml.draw";
433                if ($strFileType == ".std")
434                        $ContentType = "application/vnd.sun.xml.draw.template";
435                if ($strFileType == ".sxi")
436                        $ContentType = "application/vnd.sun.xml.impress";
437                if ($strFileType == ".sti")
438                        $ContentType = "application/vnd.sun.xml.impress.template";
439                if ($strFileType == ".sxm")
440                        $ContentType = "application/vnd.sun.xml.math";
441                if ($strFileType == ".sxw")
442                        $ContentType = "application/vnd.sun.xml.writer";
443                if ($strFileType == ".sxq")
444                        $ContentType = "application/vnd.sun.xml.writer.global";
445                if ($strFileType == ".stw")
446                        $ContentType = "application/vnd.sun.xml.writer.template";
447                if ($strFileType == ".ps")
448                        $ContentType = "application/postscript";
449                if ($strFileType == ".pps")
450                        $ContentType = "application/vnd.ms-powerpoint";
451                if ($strFileType == ".odt")
452                        $ContentType = "application/vnd.oasis.opendocument.text";
453                if ($strFileType == ".ott")
454                        $ContentType = "application/vnd.oasis.opendocument.text-template";
455                if ($strFileType == ".oth")
456                        $ContentType = "application/vnd.oasis.opendocument.text-web";
457                if ($strFileType == ".odm")
458                        $ContentType = "application/vnd.oasis.opendocument.text-master";
459                if ($strFileType == ".odg")
460                        $ContentType = "application/vnd.oasis.opendocument.graphics";
461                if ($strFileType == ".otg")
462                        $ContentType = "application/vnd.oasis.opendocument.graphics-template";
463                if ($strFileType == ".odp")
464                        $ContentType = "application/vnd.oasis.opendocument.presentation";
465                if ($strFileType == ".otp")
466                        $ContentType = "application/vnd.oasis.opendocument.presentation-template";
467                if ($strFileType == ".ods")
468                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
469                if ($strFileType == ".ots")
470                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
471                if ($strFileType == ".odc")
472                        $ContentType = "application/vnd.oasis.opendocument.chart";
473                if ($strFileType == ".odf")
474                        $ContentType = "application/vnd.oasis.opendocument.formula";
475                if ($strFileType == ".odi")
476                        $ContentType = "application/vnd.oasis.opendocument.image";
477                if ($strFileType == ".ndl")
478                        $ContentType = "application/vnd.lotus-notes";
479                return $ContentType;
480        }
481       
482        function download_all_attachments($params) {
483               
484                $id_number = $params['num_msg'];               
485                $attachments =unserialize(rawurldecode($params['s_attachments']));
486               
487                $tempDir = ini_get("session.save_path");
488                $tempSubDir = $_SESSION['phpgw_session']['session_id'];
489                $fileNames = '';
490                exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);
491                $this-> folder = $params['folder'];
492                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
493                $this->connectImap();
494                include("class.imap_attachment.inc.php");
495                $imap_attachment = new imap_attachment();
496                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
497                foreach($attachments as $i => $attachment){
498                        if($i && $i == 'names')
499                                continue;
500                                                                                                                                               
501                       
502                        $fileName = $this->remove_accents($attachment['name']);
503                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
504                        if(!$f)
505                                return False;                   
506                                               
507                        $fileNames .= "'".$fileName."' ";
508                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
509                        if($attachment['encoding'] == 'base64')
510                                fputs($f,imap_base64($fileContent));
511                        else           
512                                fputs($f,$fileContent);
513                               
514                        fclose($f);
515               
516                }
517                imap_close($this->mbox_stream);
518                $nameFileZip = '';
519               
520                if($fileNames) {
521                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir . '/'.$tempSubDir);                                         
522                        if($nameFileZip)
523                                $file =  $tempDir . '/'.$tempSubDir.'/'.$nameFileZip;
524                        else {
525                                $file = false;
526                        }
527                }
528                else
529                        $file = false; 
530                return $file;
531        }
532
533        function getHeader($msg_number){                       
534                return imap_fetchheader($this->mbox_stream, $msg_number, FT_UID);
535        }
536       
537        function getBody($msg_number){
538                $header = imap_headerinfo($this->mbox_stream, imap_msgno($this->mbox_stream, $msg_number), 80, 255);
539                $body = imap_body($this->mbox_stream, $msg_number, FT_UID);
540                if(($header->Unseen == 'U') || ($header->Recent == 'N')){
541                        imap_clearflag_full($this->mbox_stream, $msg_number, "\\Seen", ST_UID);
542                }
543                return $body;
544        }
545
546        function decode_subject($string){
547                if ((strpos(strtolower($string), '=?iso-8859-1') !== false)
548                        || (strpos(strtolower($string), '=?windows-1252') !== false)){
549                        $elements = imap_mime_header_decode($string);
550                        foreach ($elements as $el)
551                                $return .= $el->text;
552                }
553                else if (strpos(strtolower($string), '=?utf-8') !== false) {
554                        $elements = imap_mime_header_decode($string);
555                        foreach ($elements as $el){
556                                $charset = $el->charset;
557                                $text    = $el->text;
558                                if(!strcasecmp($charset, "utf-8") ||
559                                !strcasecmp($charset, "utf-7")) {
560                                $text = iconv($charset, "ISO-8859-1", $text);
561                        }
562                        $return .= $text;
563                        }
564                }
565                else
566                        $return = $string;
567
568                return $this->remove_accents($return);         
569        }
570}
571// END CLASS
572?>
Note: See TracBrowser for help on using the repository browser.