Changeset 7414 for trunk/expressoMail1_2/inc
- Timestamp:
- 10/11/12 18:14:36 (12 years ago)
- Location:
- trunk/expressoMail1_2/inc
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/expressoMail1_2/inc/class.exporteml.inc.php
r7040 r7414 56 56 // Rommel Cysne (rommel.cysne@serpro.gov.br) 57 57 // em 17/12/2008. 58 59 function createFileEml_by_localFolder($sEMLData, $tempDir, $file){ 60 61 $file = "{$file}.eml"; 62 63 $f = fopen($tempDir.'/'.$file,"w"); 64 if(!$f) 65 return False; 66 67 fputs($f,$sEMLData); 68 fclose($f); 69 70 return $file; 71 } 72 58 73 function createFileEml($sEMLData, $tempDir, $id, $subject=false, $i=false) 59 74 { … … 101 116 } 102 117 103 function createFileZip($files, $tempDir){ 118 function createFileZip($files, $tempDir){ 119 104 120 $tmp_zip_filename = "email_".$_SESSION[ 'phpgw_session' ][ 'session_id' ].".zip"; 105 106 121 if (!empty($files)) 107 122 { … … 119 134 } 120 135 } 121 122 $command = "cd " . escapeshellarg($tempDir) . " && nice zip -m9 " . escapeshellarg($tmp_zip_filename) . " " . $files; 136 137 138 $command = "cd " . escapeshellarg($tempDir) . " && nice zip -m9 " . escapeshellarg($tmp_zip_filename) . " " . $files; 139 140 123 141 if(!exec($command)) { 124 142 $command = "cd " . escapeshellarg($tempDir) . " && rm ".$files." ". escapeshellarg($tmp_zip_filename); … … 126 144 return null; 127 145 } 128 146 129 147 return $tmp_zip_filename; 130 148 131 149 } 132 150 133 function export_all($params){ 134 151 function export_all_byLocalFolder($params){ 152 $error = false; 153 154 if(empty($params['messages'])){ 155 $file["empty_folder"] = true; 156 } else { 157 foreach($params['messages'] as $eachMsg){ 158 $header = ""; 159 $body = ""; 160 $tempDir = $this->tempDir; 161 162 $this->get_header_byLocalFolder($eachMsg, $header); 163 $this->get_body_byLocalFolder($eachMsg, $body); 164 $sEMLData = $this->parseEml($header, $body); 165 $fileName = $this->createFileEml_by_localFolder($sEMLData, $tempDir,$eachMsg['msg_number']); 166 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 ($nameFileZip) ? ($file = $tempDir.'/'.$nameFileZip) : ($file = false); 178 } else 179 $file = false; 180 } 181 182 return $file; 183 184 } 185 186 function get_header_byLocalFolder($eachMsg, &$header){ 187 $header = <<<header 188 MIME-Version: 1.0 189 Content-Type: text/html; charset=ISO-8859-1 190 Content-Transfer-Encoding: quoted-printable 191 From: "{$eachMsg['from']['name']}" <{$eachMsg['from']['email']}> 192 To: {$eachMsg['to']['email']} 193 Subject: {$eachMsg['subject']} 194 Message-Id: {$eachMsg['msg_number']} 195 Date: {$eachMsg['date']} 196 header; 197 } 198 199 function get_body_byLocalFolder($eachMsg, &$body){ 200 $body = $eachMsg['msg_sample']['body']; 201 } 202 203 function export_all($params){ 204 135 205 $this->folder = $params['folder']; 136 206 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","UTF-8"); … … 140 210 141 211 $msgs = imap_search($this->mbox_stream,"ALL",SE_UID); 212 142 213 if($msgs){ 143 214 foreach($msgs as $nMsgs){ 144 $header = $this-> getHeader($nMsgs); 145 $body = $this-> getBody($nMsgs); 215 216 $header = $this-> getHeader($nMsgs); 217 $body = $this-> getBody($nMsgs); 218 146 219 $sEMLData = $this -> parseEml($header, $body); 147 220 $fileName = $this -> CreateFileEml($sEMLData, $tempDir,$nMsgs); … … 478 551 } 479 552 553 //MAILARCHIVER 554 function js_source_var($params) { 555 $this-> folder = $params['folder']; 556 if(!$this->folder){ 557 $aux = explode(';',$params['msgs_to_export']); 558 $this->folder = $aux[0]; 559 $id_number = $aux[1]; 560 } 561 else{ 562 $id_number = $params['msgs_to_export']; 563 } 564 $this->folder = mb_convert_encoding($this->folder, "UTF7-IMAP","ISO_8859-1"); 565 $tempDir = ini_get("session.save_path"); 566 567 $this->connectImap(); 568 $header = $this-> getHeader($id_number); 569 $body = $this-> getBody($id_number); 570 571 if(!strpos($header,"Date: ")){ 572 $header = "Date: " . $this->getHeaderInfo($id_number)->Date . "\r\n" .$header ; 573 } 574 575 imap_close($this->mbox_stream); 576 577 $input = $header . "\r\n\r\n" . $body; 578 $input = preg_replace('/\x1d/', '', $input); //remove special char control detected (hex 1D) 579 580 return($input); 581 } 582 480 583 function export_msg_data($id_msg,$folder) { 481 584 $this->folder = $folder; … … 752 855 return imap_fetchheader($this->mbox_stream, $msg_number, FT_UID); 753 856 } 857 858 function getHeaderInfo($msg_number){ 859 $header = imap_headerinfo($this->mbox_stream, imap_msgno($this->mbox_stream, $msg_number), 80, 255); 860 return $header; 861 } 754 862 755 863 function getBody($msg_number){ -
trunk/expressoMail1_2/inc/class.imap_functions.inc.php
r7413 r7414 3163 3163 $mailService->addHeaderField('Disposition-Notification-To', $_SESSION['phpgw_info']['expressomail']['user']['email']); 3164 3164 3165 $mailService->addHeaderField('Date', date("r")); 3165 3166 3166 3167 if ($folder != 'null') { … … 4660 4661 4661 4662 function insert_email($source,$folder,$timestamp,$flags){ 4662 4663 4663 4664 $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 4664 4665 $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; … … 4667 4668 $imap_options = '/notls/novalidate-cert'; 4668 4669 4669 4670 4670 $folder = mb_convert_encoding( $folder, "UTF7-IMAP","ISO-8859-1"); 4671 4672 4671 $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); 4673 4672 4674 4673 if(imap_last_error() === 'Mailbox already exists') 4675 4674 imap_createmailbox($mbox_stream,imap_utf7_encode("{".$imap_server."}".$folder)); 4675 4676 4676 if($timestamp){ 4677 $pdate = date_parse(date('r')); // pega a data atual do servidor (TODO: pegar a data da mensagem local) 4678 $timestamp += $pdate['zone']*(60); //converte a data da mensagem para o fuso horário GMT 0. Isto é feito devido ao Expresso Mail armazenar a data no fuso horário GMT 0 e para exibi-la converte ela para o fuso horário local. 4679 /* TODO: o diretorio /tmp deve ser substituido pelo diretorio temporario configurado no setup */ 4680 $file = "/tmp/sess_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]; 4681 4682 $f = fopen($file,"w"); 4683 fputs($f,base64_encode($source)); 4684 fclose($f); 4685 $command = "python ".dirname(__FILE__)."/../imap.py \"$imap_server\" \"$imap_port\" \"$username\" \"$password\" \"$timestamp\" \"$folder\" \"$file\""; 4686 $return['command']= exec($command); 4677 if(version_compare(PHP_VERSION, '5.3.2', '>=')){ 4678 $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1"), $source,'',date('d-M-Y H:i:s O',$timestamp)); 4679 }else{ 4680 $pdate = date_parse(date('r')); // pega a data atual do servidor (TODO: pegar a data da mensagem local) 4681 $timestamp += $pdate['zone']*(60); //converte a data da mensagem para o fuso horário GMT 0. Isto é feito devido ao Expresso Mail armazenar a data no fuso horário GMT 0 e para exibi-la converte ela para o fuso horário local. 4682 /* TODO: o diretorio /tmp deve ser substituido pelo diretorio temporario configurado no setup */ 4683 $file = "/tmp/sess_".$_SESSION[ 'phpgw_session' ][ 'session_id' ]; 4684 4685 $f = fopen($file,"w"); 4686 fputs($f,base64_encode($source)); 4687 fclose($f); 4688 $command = "python ".dirname(__FILE__)."/../imap.py \"$imap_server\" \"$imap_port\" \"$username\" \"$password\" \"$timestamp\" \"$folder\" \"$file\""; 4689 $return['command']= exec($command); 4690 } 4687 4691 }else{ 4688 4692 $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $source, "\\Seen"); 4689 4693 } 4694 4695 if (!empty($return['command'])) 4696 { 4697 list ($result, $msg) = explode(':',$return['command']); 4698 if (strtoupper($result) === 'NO') 4699 { 4700 $return['error'] = $msg; 4701 return $return; 4702 } 4703 } 4704 4690 4705 $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 4691 4706 4692 4707 $return['msg_no'] = $status->uidnext - 1; 4693 $return['error'] = imap_last_error(); 4694 if(!$return['error'] && $flags != '' ){ 4695 4696 $flags_array=explode(':',$flags); 4697 //"Answered","Draft","Flagged","Unseen" 4698 $flags_fixed = ""; 4699 if($flags_array[0] == 'A') 4700 $flags_fixed.="\\Answered "; 4701 if($flags_array[1] == 'X') 4702 $flags_fixed.="\\Draft "; 4703 if($flags_array[2] == 'F') 4704 $flags_fixed.="\\Flagged "; 4705 if($flags_array[3] != 'U') 4706 $flags_fixed.="\\Seen "; 4707 if($flags_array[4] == 'F') 4708 $flags_fixed.="\\Answered \\Draft "; 4709 imap_setflag_full($mbox_stream, $return['msg_no'], $flags_fixed, ST_UID); 4710 } 4708 4709 $return['error'] = ''; 4710 if(imap_last_error() && imap_last_error() != "SECURITY PROBLEM: insecure server advertised AUTH=PLAIN") 4711 $return['error'] = imap_last_error(); 4712 4713 if(!$return['error'] && $flags != '' ){ 4714 $flags_array=explode(':',$flags); 4715 //"Answered","Draft","Flagged","Unseen" 4716 $flags_fixed = ""; 4717 if($flags_array[0] == 'A') 4718 $flags_fixed.="\\Answered "; 4719 if($flags_array[1] == 'X') 4720 $flags_fixed.="\\Draft "; 4721 if($flags_array[2] == 'F') 4722 $flags_fixed.="\\Flagged "; 4723 if($flags_array[3] != 'U') 4724 $flags_fixed.="\\Seen "; 4725 if($flags_array[4] == 'F') 4726 $flags_fixed.="\\Answered \\Draft "; 4727 imap_setflag_full($mbox_stream, $return['msg_no'], $flags_fixed, ST_UID); 4728 } 4711 4729 4712 4730 //Ignorando erro de AUTH=Plain … … 4773 4791 4774 4792 function treat_base64_from_post($source){ 4775 $offset = 0; 4776 do 4793 $source = preg_replace('/(?<!\r)\n/', "\r\n", $source); 4794 4795 $offset = 0; 4796 do 4797 { 4798 if($inicio = strpos($source, 'Content-Transfer-Encoding: base64', $offset)) 4777 4799 { 4778 if($inicio = strpos($source, 'Content-Transfer-Encoding: base64', $offset)) 4779 { 4780 $inicio = strpos($source, "\n\r", $inicio); 4781 $fim = strpos($source, '--', $inicio); 4782 if(!$fim) 4783 $fim = strpos($source,"\n\r", $inicio); 4784 $length = $fim-$inicio; 4785 $parte = substr( $source,$inicio,$length-1); 4786 $parte = str_replace(" ", "+", $parte); 4787 $source = substr_replace($source, $parte, $inicio, $length-1); 4788 } 4789 if($offset > $inicio) 4790 $offset=FALSE; 4791 else 4792 $offset = $inicio; 4800 $inicio = strpos($source, "\n\r", $inicio); 4801 $fim = strpos($source, '--', $inicio); 4802 if(!$fim) 4803 $fim = strpos($source,"\n\r", $inicio); 4804 $length = $fim-$inicio; 4805 $parte = substr( $source,$inicio,$length-1); 4806 $parte = str_replace(" ", "+", $parte); 4807 $source = substr_replace($source, $parte, $inicio, $length-1); 4793 4808 } 4794 while($offset); 4795 return $source; 4809 if($offset > $inicio) 4810 $offset=FALSE; 4811 else 4812 $offset = $inicio; 4813 } 4814 while($offset); 4815 return $source; 4796 4816 } 4797 4817 4798 //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Recebe os fontes dos emails a serem desarquivados, separa e envia cada um para função insert_mail.4818 //Por Bruno Costa(bruno.vieira-costa@serpro.gov.br - Recebe os fontes dos emails a serem desarquivados, separa e envia cada um para função insert_mail. 4799 4819 4800 4820 function unarchive_mail($params) 4801 { 4802 $dest_folder = $params['folder'];4821 { 4822 $dest_folder = urldecode($params['folder']); 4803 4823 $sources = explode("#@#@#@",$params['source']); 4804 //Add user timeszone4805 4824 $timestamps = explode("#@#@#@",$params['timestamp']); 4806 4807 4808 4825 $flags = explode("#@#@#@",$params['flags']); 4809 4810 foreach($sources as $index=>$src) { 4811 if($src!=""){ 4812 $source = $this->treat_base64_from_post($src); 4813 $timestampsactual = $timestamps[$index] + $this->functions->CalculateDateOffset(); 4814 $insert = $this->insert_email($source, mb_convert_encoding( $dest_folder,"ISO-8859-1","UTF-8"), $timestampsactual,$flags[$index]); 4826 $ids = explode("#@#@#@",$params['id']); 4827 $return = array(); 4828 $archived = array(); 4829 $error = array(); 4830 4831 foreach($sources as $index=>$src) 4832 { 4833 if($src!="") 4834 { 4835 //If it is a MailArchiver incomming data 4836 if($params['madata']) 4837 $sourcedec = utf8_decode($src); 4838 //Default data 4839 else 4840 $sourcedec = $src; 4841 4842 $source = $this->treat_base64_from_post($sourcedec); 4843 4844 $insert = $this->insert_email($source,$dest_folder,$timestamps[$index],$flags[$index]); 4845 4846 if($insert['error']) 4847 { 4848 $error[] = $ids[$index]; 4849 } 4850 else 4851 { 4852 $archived[] = $ids[$index]; 4853 } 4854 }else{ 4855 $error[] = $ids[$index]; 4815 4856 } 4816 } 4817 return $insert; 4857 } 4858 4859 if (!empty($error)) 4860 { 4861 $return['error'] = $error; 4862 } 4863 if (!empty($archived)) 4864 { 4865 $return['archived'] = $archived; 4866 } 4867 4868 return $return; 4818 4869 } 4819 4870 … … 5484 5535 } 5485 5536 5537 //MailArchiver -> get offsettogmt as a global javascript variable, invoked at "main.js", init() 5538 function get_offset_gmt(){ 5539 return($this->functions->CalculateDateOffset()); 5540 } 5541 5542 //MailArchiver -> get message flags only, invoked at archive operation 5543 function get_msg_flags($args){ 5544 $msg_folder = $args['folder']; 5545 $msg_n = $args['msg_number']; 5546 $arr_msg = explode(",", $msg_n); 5547 5548 for($i=0; $i<count($arr_msg); $i++){ 5549 5550 if(!$this->mbox || !is_resource($this->mbox)) 5551 $this->mbox = $this->open_mbox($msg_folder); 5552 5553 if(!is_resource($this->mbox)) 5554 return(false); 5555 5556 $msgno_imap = imap_msgno($this->mbox, $msg_n); 5557 $header = @imap_headerinfo($this->mbox, $msgno_imap, 80, 255); 5558 5559 if (!is_object($header)) 5560 return false; 5561 5562 $taglist[$i]["msgid"] = $msg_n; 5563 $taglist[$i]["unseen"] = $header->Unseen; 5564 $taglist[$i]["recent"] = $header->Recent; 5565 $taglist[$i]["flagged"] = $header->Flagged; 5566 $taglist[$i]["draft"] = $header->Draft; 5567 $taglist[$i]["answered"] = $header->Answered; 5568 $taglist[$i]["deleted"] = $header->Deleted; 5569 5570 if($header->Answered =='A' && $header->Draft == 'X') 5571 $taglist[$i]['forwarded'] = 'F'; 5572 else 5573 $taglist[$i]['forwarded'] = ' '; 5574 } 5575 5576 return $taglist; 5577 } 5486 5578 } 5487 5579 ?> -
trunk/expressoMail1_2/inc/class.user.inc.php
r5509 r7414 50 50 return $_SESSION['phpgw_info']['expressomail']['user']['email']; 51 51 } 52 52 53 //MailArchiver login validate operations 54 function get_mailarchiver_authid(){ 55 if((isset($_COOKIE["BALANCEID"])) && ($_COOKIE["BALANCEID"] != null) && ($_COOKIE["BALANCEID"] != " ")) 56 $cookie_balancer = $_COOKIE["BALANCEID"]; 57 else 58 $cookie_balancer = ""; 59 if((isset($_COOKIE["sessionid"])) && ($_COOKIE["sessionid"] != null) && ($_COOKIE["sessionid"] != " ")) 60 $cookie_session = $_COOKIE["sessionid"]; 61 else 62 $cookie_session = ""; 63 if(isset($_SESSION['phpgw_info']['expressomail']['user']['userid']) && ($_SESSION['phpgw_info']['expressomail']['user']['userid'] != null) && ($_SESSION['phpgw_info']['expressomail']['user']['userid'] != " ")) 64 $cookie_user = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 65 else 66 $cookie_user = ""; 67 68 if(isset($_SESSION['phpgw_info']['expressomail']['user']['passwd']) && ($_SESSION['phpgw_info']['expressomail']['user']['passwd'] != null) && ($_SESSION['phpgw_info']['expressomail']['user']['passwd'] != " ")) 69 $cookie_pass = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; 70 else 71 $cookie_pass = ""; 72 73 return(array($cookie_balancer, $cookie_session, $cookie_user, $cookie_pass)); 74 } 75 53 76 } 54 77 ?>
Note: See TracChangeset
for help on using the changeset viewer.