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

Revision 1936, 20.8 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #815 - Problema ao exportar mensagens com aspas simples no assunto.

  • 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               
268                $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';
269                //$tempDir = ini_get("session.save_path");
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' ].".txt";
276                $tempSubDir = md5($_SESSION[ 'phpgw_session' ][ 'session_id' ].microtime());
277                $file = "source_".$tempSubDir.".txt";
278                $f = fopen($tempDir.'/'.$file,"w");
279                fputs($f,$header ."\r\n\r\n". $body);
280                fclose($f);
281               
282                imap_close($this->mbox_stream);
283                return "inc/gotodownload.php?idx_file=".$tempDir.'/'.$file."&newfilename=fonte_da_mensagem.txt";
284               
285                /*$this->folder = $folder;
286                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
287                $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';
288               
289                $phpheader = "<?php header('Content-Type: text/plain');
290                                header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
291                                header('Pragma: public');
292                                header('Expires: 0'); // set expiration time
293                                header('Content-Disposition: attachment; filename=\"fonte_da_mensagem.eml\"');?>";
294               
295                $this->connectImap();
296                $header         = $this-> getHeader($id_msg);
297                $body           = $this-> getBody($id_msg);
298               
299                $tempSubDir = md5($_SESSION[ 'phpgw_session' ][ 'session_id' ].microtime());
300                $file = "source_".$tempSubDir.".php";
301                //$file = "source_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".php";
302                $f = fopen($tempDir.'/'.$file,"w");
303                fputs($f,$phpheader.$header ."\r\n\r\n". $body);
304                fclose($f);
305                $urlPath = 'tmpLclAtt/'.$file;
306               
307                imap_close($this->mbox_stream);
308                return $urlPath;*/
309        }
310
311        function remove_accents($string) {
312                /*
313                        $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç" , "?", "\"", "!", "@", "#", "$", "%", "š", "&", "*", "(", ")", "-", "=", "+", "Ž", "`", "[", "]", "{", "}", "~", "^", ",", "<", ">", ";", ":", "/", "?", "\\", "|", "¹", "²", "³", "£", "¢", "¬", "§", "ª", "º", "°", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
314                        $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");
315                        return str_replace( $array1, $array2, $string );
316                */
317                return strtr($string,
318                        "áàâãäéèêëíìîïóòôõöúùûüç?\"'!@#$%š&*()-=+Ž`[]{}~^,<>;:/?\\|¹²³£¢¬§ªº°ÁÀÂÃÄÉÈÊËÍÌÎÏÓÒÔÕÖÚÙÛÜÇ",
319                        "aaaaaeeeeiiiiooooouuuuc___________________________________________AAAAAEEEEIIIIOOOOOUUUUC");
320        }
321       
322        function get_attachments_in_array($params) {
323                $return_attachments = array();
324
325                $id_number = $params['num_msg'];               
326                $attachments =unserialize(rawurldecode($params['s_attachments']));
327               
328                $tempDir = dirname( __FILE__ ) . '/../tmpLclAtt';
329//              $tempDir = $_SERVER["DOCUMENT_ROOT"]."tmpLclAtt";
330                $tempSubDir = md5(microtime());
331                exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);
332               
333                $this-> folder = $params['folder'];
334                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
335                $this->connectImap();
336
337                include_once("class.imap_attachment.inc.php");
338
339                $imap_attachment = new imap_attachment();
340                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
341                foreach($attachments as $i => $attachment){
342                        if($i && $i == 'names')
343                                continue;
344                        $fileNameReal = $this->remove_accents($attachment['name']);
345                        $fileNameReal = trim($fileNameReal);
346                        $ContentType = $this->getFileType($fileNameReal);
347                        $fileName = $fileNameReal;
348                        if(strpos($ContentType,"text")!==false ||
349                                        strpos($ContentType,"image")!==false ||
350                                        strpos($ContentType,"audio")!==false)
351                                $fileName.= ".php";
352                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
353                        if(!$f)
354                                return $tempDir . '/'.$tempSubDir.'/'.$fileName;                       
355
356                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
357                        $urlPath = 'tmpLclAtt/'.$tempSubDir.'/'.$fileName;
358                       
359                        if(strpos($ContentType,"text")!==false ||
360                                        strpos($ContentType,"image")!==false ||
361                                        strpos($ContentType,"audio")!==false) {
362                                $headers = "<?php header('Content-Type: ".$ContentType."');
363                                        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
364                                        header('Pragma: public');
365                                        header('Expires: 0'); // set expiration time
366                                        header('Content-Disposition: attachment; filename=\"". addslashes($fileNameReal) ."\"');\n echo ";
367                       
368                                if($attachment['encoding'] == 'base64') {
369                                        $headers.="imap_base64('".$fileContent."');?>";
370                                }
371                                else if($attachment['encoding'] == 'quoted_printable_decode') {
372                                        $headers.="quoted_printable_decode('".$fileContent."');?>";
373                                }
374                                else {
375                                        $headers.="'".$fileContent."';?>";
376                                }
377                        }
378                        else {
379                                if($attachment['encoding'] == 'base64') {
380                                        $headers=imap_base64($fileContent);
381                                }
382                                else if($attachment['encoding'] == 'quoted_printable_decode') {
383                                        $headers=quoted_printable_decode($fileContent);
384                                }
385                                else {
386                                        $headers=$fileContent;
387                                }
388                        }
389                       
390                        fputs($f,$headers);
391
392                        array_push($return_attachments,array('name' => $fileName,'url' => $urlPath,'pid' =>$attachment['pid']));
393                        fclose($f);
394                }
395                imap_close($this->mbox_stream);
396                return $return_attachments;
397        }
398       
399        private function getFileType($nameFile) {
400                $strFileType = strrev(substr(strrev(strtolower($nameFile)),0,4));
401                $ContentType = "application/octet-stream";
402                if ($strFileType == ".asf")
403                        $ContentType = "video/x-ms-asf";
404                if ($strFileType == ".avi")
405                        $ContentType = "video/avi";
406                if ($strFileType == ".doc")
407                        $ContentType = "application/msword";
408                if ($strFileType == ".zip")
409                        $ContentType = "application/zip";
410                if ($strFileType == ".xls")
411                        $ContentType = "application/vnd.ms-excel";
412                if ($strFileType == ".gif")
413                        $ContentType = "image/gif";
414                if ($strFileType == ".png")
415                        $ContentType = "image/png";
416                if ($strFileType == ".jpg" || $strFileType == "jpeg")
417                        $ContentType = "image/jpeg";
418                if ($strFileType == ".wav")
419                        $ContentType = "audio/wav";
420                if ($strFileType == ".mp3")
421                        $ContentType = "audio/mpeg3";
422                if ($strFileType == ".mpg" || $strFileType == "mpeg")
423                        $ContentType = "video/mpeg";
424                if ($strFileType == ".rtf")
425                        $ContentType = "application/rtf";
426                if ($strFileType == ".htm" || $strFileType == "html")
427                        $ContentType = "text/html";
428                if ($strFileType == ".xml")
429                        $ContentType = "text/xml";
430                if ($strFileType == ".xsl")
431                        $ContentType = "text/xsl";
432                if ($strFileType == ".css")
433                        $ContentType = "text/css";
434                if ($strFileType == ".php")
435                        $ContentType = "text/php";
436                if ($strFileType == ".asp")
437                        $ContentType = "text/asp";
438                if ($strFileType == ".pdf")
439                        $ContentType = "application/pdf";
440                if ($strFileType == ".txt")
441                        $ContentType = "text/plain";
442                if ($strFileType == ".log")
443                        $ContentType = "text/plain";
444                if ($strFileType == ".wmv")
445                        $ContentType = "video/x-ms-wmv";
446                if ($strFileType == ".sxc")
447                        $ContentType = "application/vnd.sun.xml.calc";
448                if ($strFileType == ".odt")
449                        $ContentType = "application/vnd.oasis.opendocument.text";
450                if ($strFileType == ".stc")
451                        $ContentType = "application/vnd.sun.xml.calc.template";
452                if ($strFileType == ".sxd")
453                        $ContentType = "application/vnd.sun.xml.draw";
454                if ($strFileType == ".std")
455                        $ContentType = "application/vnd.sun.xml.draw.template";
456                if ($strFileType == ".sxi")
457                        $ContentType = "application/vnd.sun.xml.impress";
458                if ($strFileType == ".sti")
459                        $ContentType = "application/vnd.sun.xml.impress.template";
460                if ($strFileType == ".sxm")
461                        $ContentType = "application/vnd.sun.xml.math";
462                if ($strFileType == ".sxw")
463                        $ContentType = "application/vnd.sun.xml.writer";
464                if ($strFileType == ".sxq")
465                        $ContentType = "application/vnd.sun.xml.writer.global";
466                if ($strFileType == ".stw")
467                        $ContentType = "application/vnd.sun.xml.writer.template";
468                if ($strFileType == ".ps")
469                        $ContentType = "application/postscript";
470                if ($strFileType == ".pps")
471                        $ContentType = "application/vnd.ms-powerpoint";
472                if ($strFileType == ".odt")
473                        $ContentType = "application/vnd.oasis.opendocument.text";
474                if ($strFileType == ".ott")
475                        $ContentType = "application/vnd.oasis.opendocument.text-template";
476                if ($strFileType == ".oth")
477                        $ContentType = "application/vnd.oasis.opendocument.text-web";
478                if ($strFileType == ".odm")
479                        $ContentType = "application/vnd.oasis.opendocument.text-master";
480                if ($strFileType == ".odg")
481                        $ContentType = "application/vnd.oasis.opendocument.graphics";
482                if ($strFileType == ".otg")
483                        $ContentType = "application/vnd.oasis.opendocument.graphics-template";
484                if ($strFileType == ".odp")
485                        $ContentType = "application/vnd.oasis.opendocument.presentation";
486                if ($strFileType == ".otp")
487                        $ContentType = "application/vnd.oasis.opendocument.presentation-template";
488                if ($strFileType == ".ods")
489                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet";
490                if ($strFileType == ".ots")
491                        $ContentType = "application/vnd.oasis.opendocument.spreadsheet-template";
492                if ($strFileType == ".odc")
493                        $ContentType = "application/vnd.oasis.opendocument.chart";
494                if ($strFileType == ".odf")
495                        $ContentType = "application/vnd.oasis.opendocument.formula";
496                if ($strFileType == ".odi")
497                        $ContentType = "application/vnd.oasis.opendocument.image";
498                if ($strFileType == ".ndl")
499                        $ContentType = "application/vnd.lotus-notes";
500                if ($strFileType == ".eml")
501                        $ContentType = "text/plain";
502                return $ContentType;
503        }
504       
505        function download_all_attachments($params) {
506               
507                $id_number = $params['num_msg'];               
508                $attachments =unserialize(rawurldecode($params['s_attachments']));
509               
510                $tempDir = ini_get("session.save_path");
511                $tempSubDir = $_SESSION['phpgw_session']['session_id'];
512                $fileNames = '';
513                exec('mkdir ' . $tempDir . '/'.$tempSubDir.'; cd ' . $tempDir . '/'.$tempSubDir);
514                $this-> folder = $params['folder'];
515                $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8");
516                $this->connectImap();
517                include("class.imap_attachment.inc.php");
518                $imap_attachment = new imap_attachment();
519                $attachments = $imap_attachment->download_attachment($this->mbox_stream, $id_number);
520                foreach($attachments as $i => $attachment){
521                        if($i && $i == 'names')
522                                continue;
523                                                                                                                                               
524                       
525                        $fileName = $this->remove_accents($attachment['name']);
526                        $f = fopen($tempDir . '/'.$tempSubDir.'/'.$fileName,"wb");
527                        if(!$f)
528                                return False;                   
529                                               
530                        $fileNames .= "'".$fileName."' ";
531                        $fileContent = imap_fetchbody($this->mbox_stream, $id_number,$attachment['pid'], FT_UID);
532                        if($attachment['encoding'] == 'base64')
533                                fputs($f,imap_base64($fileContent));
534                        else           
535                                fputs($f,$fileContent);
536                               
537                        fclose($f);
538               
539                }
540                imap_close($this->mbox_stream);
541                $nameFileZip = '';
542               
543                if($fileNames) {
544                        $nameFileZip = $this -> createFileZip($fileNames, $tempDir . '/'.$tempSubDir);                                         
545                        if($nameFileZip)
546                                $file =  $tempDir . '/'.$tempSubDir.'/'.$nameFileZip;
547                        else {
548                                $file = false;
549                        }
550                }
551                else
552                        $file = false; 
553                return $file;
554        }
555
556        function getHeader($msg_number){                       
557                return imap_fetchheader($this->mbox_stream, $msg_number, FT_UID);
558        }
559       
560        function getBody($msg_number){
561                $header = imap_headerinfo($this->mbox_stream, imap_msgno($this->mbox_stream, $msg_number), 80, 255);
562                $body = imap_body($this->mbox_stream, $msg_number, FT_UID);
563                if(($header->Unseen == 'U') || ($header->Recent == 'N')){
564                        imap_clearflag_full($this->mbox_stream, $msg_number, "\\Seen", ST_UID);
565                }
566                return $body;
567        }
568
569        function decode_subject($string){
570                if ((strpos(strtolower($string), '=?iso-8859-1') !== false)
571                        || (strpos(strtolower($string), '=?windows-1252') !== false)){
572                        $elements = imap_mime_header_decode($string);
573                        foreach ($elements as $el)
574                                $return .= $el->text;
575                }
576                else if (strpos(strtolower($string), '=?utf-8') !== false) {
577                        $elements = imap_mime_header_decode($string);
578                        foreach ($elements as $el){
579                                $charset = $el->charset;
580                                $text    = $el->text;
581                                if(!strcasecmp($charset, "utf-8") ||
582                                !strcasecmp($charset, "utf-7")) {
583                                $text = iconv($charset, "ISO-8859-1", $text);
584                        }
585                        $return .= $text;
586                        }
587                }
588                else
589                        $return = $string;
590
591                return $this->remove_accents($return);         
592        }
593}
594// END CLASS
595?>
Note: See TracBrowser for help on using the repository browser.