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

Revision 1930, 20.1 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #878 - Resolvendo o problema descrito no ticket em questao

  • 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' ].".eml";
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.eml\"');?>";
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                        $fileNameReal = trim($fileNameReal);
326                        $ContentType = $this->getFileType($fileNameReal);
327                        $fileName = $fileNameReal;
328                        if(strpos($ContentType,"text")!==false ||
329                                        strpos($ContentType,"image")!==false ||
330                                        strpos($ContentType,"audio")!==false)
331                                $fileName.= ".php";
332                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
333                        if(!$f)
334                                return $tempDir . '/'.$tempSubDir.'/'.$fileName;                       
335
336                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
337                        $urlPath = 'tmpLclAtt/'.$tempSubDir.'/'.$fileName;
338                       
339                        if(strpos($ContentType,"text")!==false ||
340                                        strpos($ContentType,"image")!==false ||
341                                        strpos($ContentType,"audio")!==false) {
342                                $headers = "<?php header('Content-Type: ".$ContentType."');
343                                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
344                                        header('Pragma: public');
345                                        header('Expires: 0'); // set expiration time
346                                        header('Content-Disposition: attachment; filename=\"". addslashes($fileNameReal) ."\"');\n echo ";
347                       
348                                if($attachment['encoding'] == 'base64') {
349                                        $headers.="imap_base64('".$fileContent."');?>";
350                                }
351                                else if($attachment['encoding'] == 'quoted_printable_decode') {
352                                        $headers.="quoted_printable_decode('".$fileContent."');?>";
353                                }
354                                else {
355                                        $headers.="'".$fileContent."';?>";
356                                }
357                        }
358                        else {
359                                if($attachment['encoding'] == 'base64') {
360                                        $headers=imap_base64($fileContent);
361                                }
362                                else if($attachment['encoding'] == 'quoted_printable_decode') {
363                                        $headers=quoted_printable_decode($fileContent);
364                                }
365                                else {
366                                        $headers=$fileContent;
367                                }
368                        }
369                       
370                        fputs($f,$headers);
371
372                        array_push($return_attachments,array('name' => $fileName,'url' => $urlPath,'pid' =>$attachment['pid']));
373                        fclose($f);
374                }
375                imap_close($this->mbox_stream);
376                return $return_attachments;
377        }
378       
379        private function getFileType($nameFile) {
380                $strFileType = strrev(substr(strrev(strtolower($nameFile)),0,4));
381                $ContentType = "application/octet-stream";
382                if ($strFileType == ".asf")
383                        $ContentType = "video/x-ms-asf";
384                if ($strFileType == ".avi")
385                        $ContentType = "video/avi";
386                if ($strFileType == ".doc")
387                        $ContentType = "application/msword";
388                if ($strFileType == ".zip")
389                        $ContentType = "application/zip";
390                if ($strFileType == ".xls")
391                        $ContentType = "application/vnd.ms-excel";
392                if ($strFileType == ".gif")
393                        $ContentType = "image/gif";
394                if ($strFileType == ".png")
395                        $ContentType = "image/png";
396                if ($strFileType == ".jpg" || $strFileType == "jpeg")
397                        $ContentType = "image/jpeg";
398                if ($strFileType == ".wav")
399                        $ContentType = "audio/wav";
400                if ($strFileType == ".mp3")
401                        $ContentType = "audio/mpeg3";
402                if ($strFileType == ".mpg" || $strFileType == "mpeg")
403                        $ContentType = "video/mpeg";
404                if ($strFileType == ".rtf")
405                        $ContentType = "application/rtf";
406                if ($strFileType == ".htm" || $strFileType == "html")
407                        $ContentType = "text/html";
408                if ($strFileType == ".xml")
409                        $ContentType = "text/xml";
410                if ($strFileType == ".xsl")
411                        $ContentType = "text/xsl";
412                if ($strFileType == ".css")
413                        $ContentType = "text/css";
414                if ($strFileType == ".php")
415                        $ContentType = "text/php";
416                if ($strFileType == ".asp")
417                        $ContentType = "text/asp";
418                if ($strFileType == ".pdf")
419                        $ContentType = "application/pdf";
420                if ($strFileType == ".txt")
421                        $ContentType = "text/plain";
422                if ($strFileType == ".log")
423                        $ContentType = "text/plain";
424                if ($strFileType == ".wmv")
425                        $ContentType = "video/x-ms-wmv";
426                if ($strFileType == ".sxc")
427                        $ContentType = "application/vnd.sun.xml.calc";
428                if ($strFileType == ".odt")
429                        $ContentType = "application/vnd.oasis.opendocument.text";
430                if ($strFileType == ".stc")
431                        $ContentType = "application/vnd.sun.xml.calc.template";
432                if ($strFileType == ".sxd")
433                        $ContentType = "application/vnd.sun.xml.draw";
434                if ($strFileType == ".std")
435                        $ContentType = "application/vnd.sun.xml.draw.template";
436                if ($strFileType == ".sxi")
437                        $ContentType = "application/vnd.sun.xml.impress";
438                if ($strFileType == ".sti")
439                        $ContentType = "application/vnd.sun.xml.impress.template";
440                if ($strFileType == ".sxm")
441                        $ContentType = "application/vnd.sun.xml.math";
442                if ($strFileType == ".sxw")
443                        $ContentType = "application/vnd.sun.xml.writer";
444                if ($strFileType == ".sxq")
445                        $ContentType = "application/vnd.sun.xml.writer.global";
446                if ($strFileType == ".stw")
447                        $ContentType = "application/vnd.sun.xml.writer.template";
448                if ($strFileType == ".ps")
449                        $ContentType = "application/postscript";
450                if ($strFileType == ".pps")
451                        $ContentType = "application/vnd.ms-powerpoint";
452                if ($strFileType == ".odt")
453                        $ContentType = "application/vnd.oasis.opendocument.text";
454                if ($strFileType == ".ott")
455                        $ContentType = "application/vnd.oasis.opendocument.text-template";
456                if ($strFileType == ".oth")
457                        $ContentType = "application/vnd.oasis.opendocument.text-web";
458                if ($strFileType == ".odm")
459                        $ContentType = "application/vnd.oasis.opendocument.text-master";
460                if ($strFileType == ".odg")
461                        $ContentType = "application/vnd.oasis.opendocument.graphics";
462                if ($strFileType == ".otg")
463                        $ContentType = "application/vnd.oasis.opendocument.graphics-template";
464                if ($strFileType == ".odp")
465                        $ContentType = "application/vnd.oasis.opendocument.presentation";
466                if ($strFileType == ".otp")
467                        $ContentType = "application/vnd.oasis.opendocument.presentation-template";
468                if ($strFileType == ".ods")
469                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
470                if ($strFileType == ".ots")
471                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
472                if ($strFileType == ".odc")
473                        $ContentType = "application/vnd.oasis.opendocument.chart";
474                if ($strFileType == ".odf")
475                        $ContentType = "application/vnd.oasis.opendocument.formula";
476                if ($strFileType == ".odi")
477                        $ContentType = "application/vnd.oasis.opendocument.image";
478                if ($strFileType == ".ndl")
479                        $ContentType = "application/vnd.lotus-notes";
480                if ($strFileType == ".eml")
481                        $ContentType = "text/plain";
482                return $ContentType;
483        }
484       
485        function download_all_attachments($params) {
486               
487                $id_number = $params['num_msg'];               
488                $attachments =unserialize(rawurldecode($params['s_attachments']));
489               
490                $tempDir = ini_get("session.save_path");
491                $tempSubDir = $_SESSION['phpgw_session']['session_id'];
492                $fileNames = '';
493                exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);
494                $this-> folder = $params['folder'];
495                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
496                $this->connectImap();
497                include("class.imap_attachment.inc.php");
498                $imap_attachment = new imap_attachment();
499                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
500                foreach($attachments as $i => $attachment){
501                        if($i && $i == 'names')
502                                continue;
503                                                                                                                                               
504                       
505                        $fileName = $this->remove_accents($attachment['name']);
506                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
507                        if(!$f)
508                                return False;                   
509                                               
510                        $fileNames .= "'".$fileName."' ";
511                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
512                        if($attachment['encoding'] == 'base64')
513                                fputs($f,imap_base64($fileContent));
514                        else           
515                                fputs($f,$fileContent);
516                               
517                        fclose($f);
518               
519                }
520                imap_close($this->mbox_stream);
521                $nameFileZip = '';
522               
523                if($fileNames) {
524                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir . '/'.$tempSubDir);                                         
525                        if($nameFileZip)
526                                $file =  $tempDir . '/'.$tempSubDir.'/'.$nameFileZip;
527                        else {
528                                $file = false;
529                        }
530                }
531                else
532                        $file = false; 
533                return $file;
534        }
535
536        function getHeader($msg_number){                       
537                return imap_fetchheader($this->mbox_stream, $msg_number, FT_UID);
538        }
539       
540        function getBody($msg_number){
541                $header = imap_headerinfo($this->mbox_stream, imap_msgno($this->mbox_stream, $msg_number), 80, 255);
542                $body = imap_body($this->mbox_stream, $msg_number, FT_UID);
543                if(($header->Unseen == 'U') || ($header->Recent == 'N')){
544                        imap_clearflag_full($this->mbox_stream, $msg_number, "\\Seen", ST_UID);
545                }
546                return $body;
547        }
548
549        function decode_subject($string){
550                if ((strpos(strtolower($string), '=?iso-8859-1') !== false)
551                        || (strpos(strtolower($string), '=?windows-1252') !== false)){
552                        $elements = imap_mime_header_decode($string);
553                        foreach ($elements as $el)
554                                $return .= $el->text;
555                }
556                else if (strpos(strtolower($string), '=?utf-8') !== false) {
557                        $elements = imap_mime_header_decode($string);
558                        foreach ($elements as $el){
559                                $charset = $el->charset;
560                                $text    = $el->text;
561                                if(!strcasecmp($charset, "utf-8") ||
562                                !strcasecmp($charset, "utf-7")) {
563                                $text = iconv($charset, "ISO-8859-1", $text);
564                        }
565                        $return .= $text;
566                        }
567                }
568                else
569                        $return = $string;
570
571                return $this->remove_accents($return);         
572        }
573}
574// END CLASS
575?>
Note: See TracBrowser for help on using the repository browser.