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

Revision 1518, 19.8 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #656 - funcionalidade de arquivamento programado no expressoMail

  • 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                foreach($msgs as $nMsgs){
114                        $header         = $this-> getHeader($nMsgs);                                                                   
115                        $body           = $this-> getBody($nMsgs);                     
116                        $sEMLData       = $this -> parseEml($header, $body);
117                        $fileName       = $this -> CreateFileEml($sEMLData, $tempDir,$nMsgs);
118                        if(!$fileName)  {
119                                $error = True;                                 
120                                break;
121                        }
122                        else
123                                $fileNames .= "\"".$fileName."\" ";                     
124                       
125                }
126                imap_close($this->mbox_stream);
127               
128                $nameFileZip = 'False';                 
129                if($fileNames && !$error) {                     
130                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir);
131                        if($nameFileZip)                       
132                                $file = $tempDir.'/'.$nameFileZip;
133                        else {
134                                $file = false;
135                        }                                                               
136                }
137                else
138                        $file = false;
139                       
140                return $file;
141               
142        }
143
144        // Funcao alterada para tratar a exportacao
145        // de mensagens arquivadas localmente.
146        // Rommel Cysne (rommel.cysne@serpro.gov.br)
147        // em 17/12/2008.
148        function makeAll($params) {
149                // Exportacao de mensagens arquivadas localmente
150                if($params['l_msg'] == "t"){
151                // Recebe todos os subjects e bodies das mensagens locais selecionadas para exportacao
152                // e gera arrays com os conteudos separados;
153                $array_mesgs = explode('@@',$params['mesgs']);
154                $array_subjects = explode('@@',$params['subjects']);
155            $array_ids = explode(',', $params['msgs_to_export']);
156            $tempDir = ini_get("session.save_path");
157                        // Para cada mensagem selecionada sera gerado um arquivo .eml cujo titulo sera o assunto (subject) da mesma;
158                        include_once("class.imap_functions.inc.php");
159                        $imapf = new imap_functions();
160                foreach($array_ids as $i=>$id) {
161                                $sEMLData=$imapf->treat_base64_from_post($array_mesgs[$i]);
162                                $fileName=$this->CreateFileEml($sEMLData, $tempDir,'',$array_subjects[$i],$i);
163                                if(!$fileName){
164                                        $error = True;
165                                        break;
166                                } else{
167                                        $fileNames .= "\"".$fileName."\" ";
168                                }
169                        }
170                        $nameFileZip = 'False';
171                        if($fileNames && !$error) {
172                                $nameFileZip = $this -> createFileZip($fileNames, $tempDir);
173                                if($nameFileZip){
174                                        $file = $tempDir.'/'.$nameFileZip;
175                                } else{
176                                        $file = false;
177                                }
178
179                        } else{
180                                $file = false;
181                        }
182
183            return $file;
184
185                // Exportacao de mensagens da caixa de entrada (imap) - processo original do Expresso
186                } else{
187            $this-> folder = $params['folder'];
188            $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
189            $array_ids = explode(',', $params['msgs_to_export']);
190            $error = False;
191            $fileNames = "";
192            $tempDir = ini_get("session.save_path");
193            $this->connectImap();
194                        for($i = 0; $i < count($array_ids); $i++) {
195                        $header         = $this-> getHeader($array_ids[$i]);                                                                                   
196                        $body           = $this-> getBody($array_ids[$i]);                     
197                        $sEMLData       = $this -> parseEml($header, $body);                   
198                        $fileName       = $this -> CreateFileEml($sEMLData, $tempDir, $array_ids[$i]);
199                       
200                        if(!$fileName)  {
201                                $error = True;                                 
202                                break;
203                        }
204                        else
205                                $fileNames .= "\"".$fileName."\" ";                     
206                       
207                }
208                imap_close($this->mbox_stream);
209               
210               
211                $nameFileZip = 'False';                 
212                if($fileNames && !$error) {                     
213                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir);
214                        if($nameFileZip)                       
215                                $file = $tempDir.'/'.$nameFileZip;
216                        else {
217                                $file = false;
218                        }                                                               
219                }
220                else
221                        $file = false;
222                       
223                return $file;
224        }
225    }
226
227        function export_msg($params) {
228                $this-> folder = $params['folder'];
229                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
230                $id_number = $params['msgs_to_export'];
231                $tempDir = ini_get("session.save_path");
232               
233                $this->connectImap();
234                $header         = $this-> getHeader($id_number);
235                $body           = $this-> getBody($id_number);
236               
237                $file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".txt";
238                $f = fopen($tempDir.'/'.$file,"w");
239                fputs($f,$header ."\r\n\r\n". $body);
240                fclose($f);
241               
242                imap_close($this->mbox_stream);
243                return $tempDir.'/'.$file;
244        }
245
246    function export_msg_data($id_msg,$folder) {
247                $this->folder = $folder;
248                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
249
250                $this->connectImap();
251                $header         = $this-> getHeader($id_msg);
252                $body           = $this-> getBody($id_msg);
253
254                $msg_data = $header ."\r\n\r\n". $body;
255
256                imap_close($this->mbox_stream);
257                return $msg_data;
258        }
259
260        function export_to_archive($id_msg,$folder) {
261                $this->folder = $folder;
262                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
263                $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';
264               
265                $phpheader = "<?php header('Content-Type: text/plain');
266                                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
267                                header('Pragma: public');
268                                header('Expires: 0'); // set expiration time
269                                header('Content-Disposition: attachment; filename=\"fonte_da_mensagem.txt\"');?>";
270               
271                $this->connectImap();
272                $header         = $this-> getHeader($id_msg);
273                $body           = $this-> getBody($id_msg);
274               
275                $file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".php";
276                $f = fopen($tempDir.'/'.$file,"w");
277                fputs($f,$phpheader.$header ."\r\n\r\n". $body);
278                fclose($f);
279                $urlPath = 'tmpLclAtt/'.$file;
280               
281                imap_close($this->mbox_stream);
282                return $urlPath;
283        }
284
285        function remove_accents($string) {
286                /*
287                        $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç" , "?", "\"", "!", "@", "#", "$", "%", "š", "&", "*", "(", ")", "-", "=", "+", "Ž", "`", "[", "]", "{", "}", "~", "^", ",", "<", ">", ";", ":", "/", "?", "\\", "|", "¹", "²", "³", "£", "¢", "¬", "§", "ª", "º", "°", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
288                        $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");
289                        return str_replace( $array1, $array2, $string );
290                */
291                return strtr($string,
292                        "áàâãäéèêëíìîïóòôõöúùûüç?\"!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ",
293                        "aaaaaeeeeiiiiooooouuuuc__________________________________________AAAAAEEEEIIIIOOOOOUUUUC");
294        }
295       
296        function get_attachments_in_array($params) {
297                $return_attachments = array();
298
299                $id_number = $params['num_msg'];               
300                $attachments =unserialize(rawurldecode($params['s_attachments']));
301               
302                $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';
303//              $tempDir = $_SERVER["DOCUMENT_ROOT"]."tmpLclAtt";
304                $tempSubDir = md5(microtime());
305                exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);
306               
307                $this-> folder = $params['folder'];
308                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
309                $this->connectImap();
310
311                include_once("class.imap_attachment.inc.php");
312
313                $imap_attachment = new imap_attachment();
314                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
315                foreach($attachments as $i => $attachment){
316                        if($i && $i == 'names')
317                                continue;
318                        $fileNameReal = $this->remove_accents($attachment['name']);
319                        $ContentType = $this->getFileType($fileNameReal);
320                        $fileName = $fileNameReal;
321                        if(strpos($ContentType,"text")!==false ||
322                                        strpos($ContentType,"image")!==false ||
323                                        strpos($ContentType,"audio")!==false)
324                                $fileName.= ".php";
325                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
326                        if(!$f)
327                                return $tempDir . '/'.$tempSubDir.'/'.$fileName;                       
328
329                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
330                        $urlPath = 'tmpLclAtt/'.$tempSubDir.'/'.$fileName;
331                       
332                        if(strpos($ContentType,"text")!==false ||
333                                        strpos($ContentType,"image")!==false ||
334                                        strpos($ContentType,"audio")!==false) {
335                                $headers = "<?php header('Content-Type: ".$ContentType."');
336                                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
337                                        header('Pragma: public');
338                                        header('Expires: 0'); // set expiration time
339                                        header('Content-Disposition: attachment; filename=\"". addslashes($fileNameReal) ."\"');\n echo ";
340                       
341                                if($attachment['encoding'] == 'base64') {
342                                        $headers.="imap_base64('".$fileContent."');?>";
343                                }
344                                else if($attachment['encoding'] == 'quoted_printable_decode') {
345                                        $headers.="quoted_printable_decode('".$fileContent."');?>";
346                                }
347                                else {
348                                        $headers.="'".$fileContent."';?>";
349                                }
350                        }
351                        else {
352                                if($attachment['encoding'] == 'base64') {
353                                        $headers=imap_base64($fileContent);
354                                }
355                                else if($attachment['encoding'] == 'quoted_printable_decode') {
356                                        $headers=quoted_printable_decode($fileContent);
357                                }
358                                else {
359                                        $headers=$fileContent;
360                                }
361                        }
362                       
363                        fputs($f,$headers);
364
365                        array_push($return_attachments,array('name' => $fileName,'url' => $urlPath,'pid' =>$attachment['pid']));
366                        fclose($f);
367                }
368                imap_close($this->mbox_stream);
369                return $return_attachments;
370        }
371       
372        private function getFileType($nameFile) {
373                $strFileType = strrev(substr(strrev(strtolower($nameFile)),0,4));
374                $ContentType = "application/octet-stream";
375                if ($strFileType == ".asf")
376                        $ContentType = "video/x-ms-asf";
377                if ($strFileType == ".avi")
378                        $ContentType = "video/avi";
379                if ($strFileType == ".doc")
380                        $ContentType = "application/msword";
381                if ($strFileType == ".zip")
382                        $ContentType = "application/zip";
383                if ($strFileType == ".xls")
384                        $ContentType = "application/vnd.ms-excel";
385                if ($strFileType == ".gif")
386                        $ContentType = "image/gif";
387                if ($strFileType == ".png")
388                        $ContentType = "image/png";
389                if ($strFileType == ".jpg" || $strFileType == "jpeg")
390                        $ContentType = "image/jpeg";
391                if ($strFileType == ".wav")
392                        $ContentType = "audio/wav";
393                if ($strFileType == ".mp3")
394                        $ContentType = "audio/mpeg3";
395                if ($strFileType == ".mpg" || $strFileType == "mpeg")
396                        $ContentType = "video/mpeg";
397                if ($strFileType == ".rtf")
398                        $ContentType = "application/rtf";
399                if ($strFileType == ".htm" || $strFileType == "html")
400                        $ContentType = "text/html";
401                if ($strFileType == ".xml")
402                        $ContentType = "text/xml";
403                if ($strFileType == ".xsl")
404                        $ContentType = "text/xsl";
405                if ($strFileType == ".css")
406                        $ContentType = "text/css";
407                if ($strFileType == ".php")
408                        $ContentType = "text/php";
409                if ($strFileType == ".asp")
410                        $ContentType = "text/asp";
411                if ($strFileType == ".pdf")
412                        $ContentType = "application/pdf";
413                if ($strFileType == ".txt")
414                        $ContentType = "text/plain";
415                if ($strFileType == ".log")
416                        $ContentType = "text/plain";
417                if ($strFileType == ".wmv")
418                        $ContentType = "video/x-ms-wmv";
419                if ($strFileType == ".sxc")
420                        $ContentType = "application/vnd.sun.xml.calc";
421                if ($strFileType == ".odt")
422                        $ContentType = "application/vnd.oasis.opendocument.text";
423                if ($strFileType == ".stc")
424                        $ContentType = "application/vnd.sun.xml.calc.template";
425                if ($strFileType == ".sxd")
426                        $ContentType = "application/vnd.sun.xml.draw";
427                if ($strFileType == ".std")
428                        $ContentType = "application/vnd.sun.xml.draw.template";
429                if ($strFileType == ".sxi")
430                        $ContentType = "application/vnd.sun.xml.impress";
431                if ($strFileType == ".sti")
432                        $ContentType = "application/vnd.sun.xml.impress.template";
433                if ($strFileType == ".sxm")
434                        $ContentType = "application/vnd.sun.xml.math";
435                if ($strFileType == ".sxw")
436                        $ContentType = "application/vnd.sun.xml.writer";
437                if ($strFileType == ".sxq")
438                        $ContentType = "application/vnd.sun.xml.writer.global";
439                if ($strFileType == ".stw")
440                        $ContentType = "application/vnd.sun.xml.writer.template";
441                if ($strFileType == ".ps")
442                        $ContentType = "application/postscript";
443                if ($strFileType == ".pps")
444                        $ContentType = "application/vnd.ms-powerpoint";
445                if ($strFileType == ".odt")
446                        $ContentType = "application/vnd.oasis.opendocument.text";
447                if ($strFileType == ".ott")
448                        $ContentType = "application/vnd.oasis.opendocument.text-template";
449                if ($strFileType == ".oth")
450                        $ContentType = "application/vnd.oasis.opendocument.text-web";
451                if ($strFileType == ".odm")
452                        $ContentType = "application/vnd.oasis.opendocument.text-master";
453                if ($strFileType == ".odg")
454                        $ContentType = "application/vnd.oasis.opendocument.graphics";
455                if ($strFileType == ".otg")
456                        $ContentType = "application/vnd.oasis.opendocument.graphics-template";
457                if ($strFileType == ".odp")
458                        $ContentType = "application/vnd.oasis.opendocument.presentation";
459                if ($strFileType == ".otp")
460                        $ContentType = "application/vnd.oasis.opendocument.presentation-template";
461                if ($strFileType == ".ods")
462                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
463                if ($strFileType == ".ots")
464                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
465                if ($strFileType == ".odc")
466                        $ContentType = "application/vnd.oasis.opendocument.chart";
467                if ($strFileType == ".odf")
468                        $ContentType = "application/vnd.oasis.opendocument.formula";
469                if ($strFileType == ".odi")
470                        $ContentType = "application/vnd.oasis.opendocument.image";
471                if ($strFileType == ".ndl")
472                        $ContentType = "application/vnd.lotus-notes";
473                return $ContentType;
474        }
475       
476        function download_all_attachments($params) {
477               
478                $id_number = $params['num_msg'];               
479                $attachments =unserialize(rawurldecode($params['s_attachments']));
480               
481                $tempDir = ini_get("session.save_path");
482                $tempSubDir = md5(microtime());
483                $fileNames = '';
484                exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);
485                $this-> folder = $params['folder'];
486                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
487                $this->connectImap();
488                include("class.imap_attachment.inc.php");
489                $imap_attachment = new imap_attachment();
490                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
491               
492                foreach($attachments as $i => $attachment){
493                        if($i && $i == 'names')
494                                continue;
495                                                                                                                                               
496                       
497                        $fileName = $this->remove_accents($attachment['name']);
498                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
499                        if(!$f)
500                                return False;                   
501                                               
502                        $fileNames .= "'".$fileName."' ";
503                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
504                        if($attachment['encoding'] == 'base64')
505                                fputs($f,imap_base64($fileContent));
506                        else           
507                                fputs($f,$fileContent);
508                               
509                        fclose($f);
510               
511                }
512                imap_close($this->mbox_stream);
513                $nameFileZip = '';
514               
515                if($fileNames) {
516                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir . '/'.$tempSubDir);                                         
517                        if($nameFileZip)
518                                $file =  $tempDir . '/'.$tempSubDir.'/'.$nameFileZip;
519                        else {
520                                $file = false;
521                        }
522                }
523                else
524                        $file = false;
525                               
526                return $file;
527        }
528
529        function getHeader($msg_number){                       
530                return imap_fetchheader($this->mbox_stream, $msg_number, FT_UID);
531        }
532       
533        function getBody($msg_number){
534                $header = imap_headerinfo($this->mbox_stream, imap_msgno($this->mbox_stream, $msg_number), 80, 255);
535                $body = imap_body($this->mbox_stream, $msg_number, FT_UID);
536                if(($header->Unseen == 'U') || ($header->Recent == 'N')){
537                        imap_clearflag_full($this->mbox_stream, $msg_number, "\\Seen", ST_UID);
538                }
539                return $body;
540        }
541
542        function decode_subject($string){
543                if ((strpos(strtolower($string), '=?iso-8859-1') !== false)
544                        || (strpos(strtolower($string), '=?windows-1252') !== false)){
545                        $elements = imap_mime_header_decode($string);
546                        foreach ($elements as $el)
547                                $return .= $el->text;
548                }
549                else if (strpos(strtolower($string), '=?utf-8') !== false) {
550                        $elements = imap_mime_header_decode($string);
551                        foreach ($elements as $el){
552                                $charset = $el->charset;
553                                $text    = $el->text;
554                                if(!strcasecmp($charset, "utf-8") ||
555                                !strcasecmp($charset, "utf-7")) {
556                                $text = iconv($charset, "ISO-8859-1", $text);
557                        }
558                        $return .= $text;
559                        }
560                }
561                else
562                        $return = $string;
563
564                return $this->remove_accents($return);         
565        }
566}
567// END CLASS
568?>
Note: See TracBrowser for help on using the repository browser.