Ignore:
Timestamp:
04/30/08 17:11:15 (16 years ago)
Author:
niltonneto
Message:

Fechamento de versão: 1.2211
Tickets:

#50 Criar uma funcionalidade para inserir imagens embutidas no corpo da mensagem.
#174 Implementar rascunho com anexos
#182 Criar funcionalidade de salvar automaticamente os emails em rascunhos
#183 Funcionalidade de drag and drop na busca
#185 Adicionar tabela na edição de email
#186 Correção do problema com nomes de anexos com caracteres especiais
#188 Definir aspectos de QA do ExpressoMail?
#190 Problema ao salvar informações de filtros no IE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/expressoMail1_2/inc/class.imap_functions.inc.php

    r205 r271  
    840840                 
    841841                $msg_to_insert  = array_diff($msgs_in_the_server, $msgs_in_the_client); 
    842                 //$msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); 
     842                $msg_to_delete = array_diff($msgs_in_the_client, $msgs_in_the_server); 
    843843                 
    844844                $msgs_to_exec = array(); 
     
    867867                        } 
    868868                } 
    869                 /*if (count($msg_to_delete)) 
    870                 { 
    871                         foreach($msg_to_delete as $index => $msg_number) 
    872                         { 
    873                                 $msgs_to_exec[$msg_number] = 'Apagar mensage numero ' . $msg_number; 
    874                         } 
    875                 }*/ 
    876869                 
    877870                $return = array(); 
     
    930923                } 
    931924                $return['new_msgs'] = imap_num_recent($this->mbox); 
     925                $return['msgs_to_delete'] = $msg_to_delete; 
    932926                if($this->mbox) 
    933927                        imap_close($this->mbox); 
     
    10941088                $ccoaddress = implode(',',$db->getAddrs(explode(',',$params['input_cco']))); 
    10951089                $subject = $params['input_subject']; 
     1090                $msg_uid = $params['msg_id']; 
    10961091                $return_receipt = $params['input_return_receipt']; 
    10971092                $body = $params['body']; 
     
    11131108//////////////////////////////////////////////////////////////////////////////////////////////////// 
    11141109                $mail->SMTPDebug = false; 
    1115                  
    1116                 //$mail->SMTPAuth = true; 
    1117                 //$mail->Username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
    1118                 //$mail->Password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; 
    11191110                                 
    11201111                $mail->IsSMTP(); 
     
    11361127                $mail->IsHTML(true); 
    11371128                $mail->Body = $params['body']; 
     1129 
     1130//////////////////////////////////////////////////////////////////////////////////////////////////// 
     1131                //      Build CID for embedded Images!!! 
     1132                $pattern = '/src="([^"]*?show_embedded_attach.php\?msg_folder=(.+)?&msg_num=(.+)?&msg_part=(.+)?)"/isU'; 
     1133                $cid_imgs = ''; 
     1134                $name_cid_files = array(); 
     1135                preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER); 
     1136                $cid_array = array(); 
     1137                foreach($cid_imgs[4] as $j => $val){ 
     1138                                if ( !array_key_exists($cid_imgs[3][$j].$val, $cid_array) ) 
     1139                        { 
     1140                $cid_array[$cid_imgs[3][$j].$val] = base_convert(microtime(), 10, 36); 
     1141                        } 
     1142                        $cid = $cid_array[$cid_imgs[3][$j].$val];  
     1143                        $mail->Body = str_replace($cid_imgs[1][$j], "cid:".$cid, $mail->Body); 
     1144                         
     1145                                if ($msg_uid != $cid_imgs[3][$j]) // The image isn't in the same mail? 
     1146                                { 
     1147                                        $fileContent = $this->get_forwarding_attachment($cid_imgs[2][$j], $cid_imgs[3][$j], $cid_imgs[4][$j], 'base64'); 
     1148                                        $fileName = "image_".($j).".jpg"; 
     1149                                        $fileCode = "base64"; 
     1150                                        $fileType = "image/jpg"; 
     1151                                } 
     1152                                else 
     1153                                { 
     1154                                        $attach_img = $forwarding_attachments[$cid_imgs[4][$j]-2]; 
     1155                                        $file_description = unserialize(rawurldecode($attach_img)); 
     1156 
     1157                                        foreach($file_description as $i => $descriptor){                                 
     1158                                                $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
     1159                                        } 
     1160                                        $fileContent = $this->get_forwarding_attachment($file_description[0], $msg_uid, $file_description[3], 'base64'); 
     1161                                        $fileName = $file_description[2]; 
     1162                                        $fileCode = $file_description[4]; 
     1163                                        $fileType = $this->get_file_type($file_description[2]); 
     1164                                        unset($forwarding_attachments[$cid_imgs[4][$j]-2]); 
     1165                                } 
     1166                                $tempDir = ini_get("session.save_path"); 
     1167                                $file = "cid_image_".base_convert(microtime(), 10, 36).".dat";                                   
     1168                                $f = fopen($tempDir.'/'.$file,"w"); 
     1169                                fputs($f,$fileContent); 
     1170                                fclose($f); 
     1171                                if ($fileContent) 
     1172                                        $mail->AddEmbeddedImage($tempDir.'/'.$file, $cid, $fileName, $fileCode, $fileType); 
     1173                                //else 
     1174                                //      return "Error loading image attachment content";                                                 
     1175 
     1176                } 
    11381177//////////////////////////////////////////////////////////////////////////////////////////////////// 
    11391178                //      Build Uploading Attachments!!! 
     
    11511190                }                        
    11521191//////////////////////////////////////////////////////////////////////////////////////////////////// 
    1153                 //      Build CID for embedded Images!!! 
    1154                 $pattern = '/show_embedded_attach.php\?msg_folder=INBOX&(.+)&(.+)">/isU'; 
    1155                 $cid_imgs = ''; 
    1156                 $name_cid_files = array(); 
    1157                 if(preg_match_all($pattern,$mail->Body,$cid_imgs,PREG_PATTERN_ORDER)){           
    1158                         include("class.imap_attachment.inc.php"); 
    1159                         $imap_attachment = new imap_attachment();                        
    1160                 } 
    1161                 for($i = 0; $i < count($cid_imgs);$i++){ 
    1162                         if($i == 1) { 
    1163                                 for($j = 0; $j < count($cid_imgs[$i]);$j++){ 
    1164                                         $cid = base_convert(microtime(), 10, 36); 
    1165                                         $msg_num = explode("=",$cid_imgs[$i][$j]);  
    1166                                         $msg_part = explode("=",$cid_imgs[$i+1][$j]); 
    1167                                         $fileContent = imap_base64(imap_fetchbody($this->open_mbox(), $msg_num[1], $msg_part[1], FT_UID)); 
    1168                                         $pattern = './inc/show_embedded_attach.php?msg_folder=INBOX&amp;msg_num='.$msg_num[1].'&amp;msg_part='.$msg_part[1]; 
    1169                                         $replace = "cid:".$cid; 
    1170                                         $mail->Body = str_replace($pattern,$replace,$mail->Body); 
    1171                                         $tempDir = ini_get("session.save_path"); 
    1172                                         $file = "cid_image_".base_convert(microtime(), 10, 36).".dat";                                   
    1173                                         $f = fopen($tempDir.'/'.$file,"w"); 
    1174                                         fputs($f,$fileContent); 
    1175                                         fclose($f);              
    1176                                         $name_cid_files[$j] = "image_".($j).".jpg";                      
    1177                                         $mail->AddEmbeddedImage("$tempDir/$file", $cid, "image_".($j).".jpg", "base64", "image/jpg"); 
    1178                                 } 
    1179                         }                
    1180                 } 
    1181 //////////////////////////////////////////////////////////////////////////////////////////////////// 
    1182                 //      Build Forwarding Attachments!!!          
     1192                //      Build Forwarding Attachments!!! 
    11831193                if (count($forwarding_attachments) > 0) 
    11841194                { 
     
    11911201                        foreach($forwarding_attachments as $forwarding_attachment) 
    11921202                        { 
    1193                                 $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    1194                                 foreach($file_description as $i => $descriptor){                                 
    1195                                         $file_description[$i]  = eregi_replace('\'*\'','',$descriptor); 
    1196                                 } 
    1197                                 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    1198                                 $fileName = $file_description[2]; 
    1199                                 if(!array_search(trim($fileName),$name_cid_files)) { 
    1200                                         $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
     1203                                        $file_description = unserialize(rawurldecode($forwarding_attachment)); 
     1204                                        $tmp = array_values($file_description); 
     1205                                        foreach($file_description as $i => $descriptor){                                 
     1206                                                $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
     1207                                        } 
     1208                                        $file_description = $tmp;                                        
     1209                                        $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
     1210                                        $fileName = $file_description[2]; 
     1211                                        if(!array_search(trim($fileName),$name_cid_files)) { 
     1212                                                $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
    12011213                                } 
    12021214                        } 
     
    14521464        function save_msg($params) 
    14531465        { 
    1454                 $folder_id = $params['folder_id']; 
    1455                 $folder_id =  mb_convert_encoding($folder_id, "UTF7-IMAP", "UTF-8"); 
    1456                 $folder_name = $params['folder_name']; 
    1457                 $folder_name =  mb_convert_encoding($folder_name, "ISO-8859-1", "UTF-8"); 
    1458                 $border_id = $params['border_id']; 
    1459                 $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
    1460                 $mbox_stream = $this->open_mbox();               
    1461                  
    1462                 $from = '"' . $_SESSION['phpgw_info']['expressomail']['user']['fullname'] . '" <' . $_SESSION['phpgw_info']['expressomail']['user']['email'] . '>';                              
    1463                 $to = $params['to']; 
    1464                 $cc = $params['cc']; 
    1465                 $subject = $params['subject']; 
     1466                 
     1467                include_once("class.phpmailer.php"); 
     1468                $mail = new PHPMailer(); 
     1469                include_once("class.db_functions.inc.php"); 
     1470                $toaddress = $params['input_to']; 
     1471                $ccaddress = $params['input_cc']; 
     1472                $subject = $params['input_subject']; 
    14661473                $body = $params['body']; 
    14671474                $body = str_replace("%nbsp;","&nbsp;",$params['body']); 
    14681475                $body = preg_replace("/\n/"," ",$body); 
    14691476                $body = preg_replace("/\r/","",$body); 
    1470                  
    1471                 $header =       "From: " . $from . "\r\n" 
    1472                                         . "To: " . $to . "\r\n" 
    1473                                         . "Cc: " . $cc . "\r\n"; 
     1477                $forwarding_attachments = $params['forwarding_attachments']; 
     1478                $attachments = $params['FILES']; 
     1479                $return_files = $params['FILES']; 
     1480                  
     1481                $folder = $params['folder']; 
     1482                $folder = mb_convert_encoding($folder, "UTF7-IMAP","ISO_8859-1");                
     1483                // Fix problem with cyrus delimiter changes. 
     1484                // Dots in names: enabled/disabled.                              
     1485                $folder = @eregi_replace("INBOX/", "INBOX".$this->imap_delimiter, $folder); 
     1486                $folder = @eregi_replace("INBOX.", "INBOX".$this->imap_delimiter, $folder); 
     1487                // End Fix. 
    14741488                                         
    1475                 $header =  mb_convert_encoding($header, "ISO-8859-1", "UTF-8"); 
    1476                 $header =       $header 
    1477                                         . "Subject: " . $subject . "\r\n" 
    1478                                         . "\r\n" 
    1479                                         . $body . "\r\n"; 
    1480                  
    1481                 $return = array(); 
    1482                 $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder_id, $header, "\\Seen \\Draft"); 
    1483                 $return['folder_name'] = $folder_name; 
    1484                 $return['border_id'] = $border_id; 
     1489                $mail->SaveMessageInFolder = $folder; 
     1490                $mail->SMTPDebug = false; 
     1491                                                 
     1492                $mail->IsSMTP(); 
     1493                $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer']; 
     1494                $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort']; 
     1495                $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
     1496                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
     1497                 
     1498                $mail->Sender = $mail->From; 
     1499                $mail->SenderName = $mail->FromName; 
     1500                $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; 
     1501                $mail->From =  $_SESSION['phpgw_info']['expressomail']['user']['email']; 
     1502                                 
     1503                $this->add_recipients("to", $toaddress, &$mail); 
     1504                $this->add_recipients("cc", $ccaddress, &$mail); 
     1505                $mail->Subject = $subject; 
     1506                $mail->IsHTML(true); 
     1507                $mail->Body = $body; 
     1508                 
     1509         
     1510        //      Build Forwarding Attachments!!!          
     1511                if (count($forwarding_attachments) > 0) 
     1512                { 
     1513                        foreach($forwarding_attachments as $forwarding_attachment) 
     1514                        { 
     1515                                $file_description = unserialize(rawurldecode($forwarding_attachment)); 
     1516                                $tmp = array_values($file_description); 
     1517                                foreach($file_description as $i => $descriptor){                                 
     1518                                        $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
     1519                                } 
     1520                                $file_description = $tmp; 
     1521                                 
     1522                                $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
     1523                                $fileName = $file_description[2]; 
     1524                                 
     1525                                $file_description[5] = strlen($fileContent); //Size of file 
     1526                                $return_forward[] = $file_description; 
     1527                         
     1528                                        $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
     1529                        } 
     1530                } 
     1531                 
     1532                if ((count($return_forward) > 0) && (count($return_files) > 0)) 
     1533                        $return_files = array_merge_recursive($return_forward,$return_files); 
     1534                else 
     1535                        if (count($return_files) < 1) 
     1536                                $return_files = $return_forward; 
     1537         
     1538                //      Build Uploading Attachments!!! 
     1539                if (count($attachments)) 
     1540                        foreach ($attachments as $attach) 
     1541                                $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name']));  // optional name                   
     1542         
     1543         
     1544                 
     1545                if(!empty($mail->AltBody)) 
     1546            $mail->ContentType = "multipart/alternative"; 
     1547 
     1548        $mail->error_count = 0; // reset errors 
     1549        $mail->SetMessageType(); 
     1550        $header = $mail->CreateHeader(); 
     1551        $body = $mail->CreateBody(); 
     1552         
     1553        if ($_SESSION['phpgw_info']['expressomail']['email_server']['imapTLSEncryption'] == 'yes') 
     1554                { 
     1555                        $imap_options = '/tls/novalidate-cert'; 
     1556                } 
     1557                else 
     1558                { 
     1559                        $imap_options = '/notls/novalidate-cert'; 
     1560                } 
     1561                $username = $_SESSION['phpgw_info']['expressomail']['user']['userid']; 
     1562                $password = $_SESSION['phpgw_info']['expressomail']['user']['passwd']; 
     1563                $imap_server = $_SESSION['phpgw_info']['expressomail']['email_server']['imapServer']; 
     1564                $imap_port      = $_SESSION['phpgw_info']['expressomail']['email_server']['imapPort']; 
     1565                $mbox_stream = imap_open("{".$imap_server.":".$imap_port.$imap_options."}".$folder, $username, $password); 
     1566         
     1567                $new_header = str_replace("\n", "\r\n", $header); 
     1568                $new_body = str_replace("\n", "\r\n", $body); 
     1569                 
     1570                $return['append'] = imap_append($mbox_stream, "{".$imap_server.":".$imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 
     1571                $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
     1572                $return['msg_no'] = $status->uidnext - 1; 
     1573                $return['folder_id'] = $folder; 
    14851574                 
    14861575                if($mbox_stream) 
    14871576                        imap_close($mbox_stream); 
    1488                  
     1577                                 
     1578                foreach ($return_files as $index => $_attachment) { 
     1579                        if (array_key_exists("name",$_attachment)){ 
     1580                                unset($return_files[$index]); 
     1581                                $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; 
     1582                        } 
     1583                        else 
     1584                        { 
     1585                                unset($return_files[$index]); 
     1586                                $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; 
     1587                        } 
     1588                } 
     1589                 
     1590                $return['files'] = serialize($return_files); 
     1591                                 
    14891592                if (!$return['append']) 
    14901593                        $return['append'] = imap_last_error(); 
    1491                 else 
    1492                         $return['header'] = $header; 
     1594                 
    14931595                return $return; 
    14941596        } 
     
    19162018        function search_msg($params = ''){ 
    19172019                $retorno = ""; 
     2020                $mbox_stream = ""; 
    19182021                $search = explode(",",$params['condition']); 
    19192022                if($search){ 
    19202023                        $search_criteria = ''; 
    1921                         foreach($search as $tmp){ 
     2024                        foreach($search as $tmp) 
     2025                        { 
    19222026                                $tmp1 = explode("##",$tmp); 
    19232027                                $name_box = $tmp1[0]; 
    19242028                                $criteria = explode("<=>",rawurldecode($tmp1[1]));                               
    19252029                                $criteria[1] = $this->remove_accents($criteria[1]); 
    1926                                 $mbox_stream = $this->open_mbox($name_box); 
     2030                                 
     2031                                if(!is_resource($mbox_stream)) 
     2032                                        $mbox_stream = $this->open_mbox(); 
     2033                                else 
     2034                                        imap_reopen($mbox_stream, "{".$this->imap_server.":".$this->imap_port.$this->imap_options."}".$name_box); 
    19272035                                 
    19282036                                if($criteria[0] == "ALL ") {                                     
    1929                                         $all_criterias = array ("TO","SUBJECT","FROM","CC");                                                             
    1930                                         foreach($all_criterias as $criteria_fixed){                                              
    1931                                                 $search_criteria = imap_search($mbox_stream,$criteria_fixed." \"".$criteria[1]."\"", SE_UID); 
    1932                                                 if($search_criteria && count($search_criteria) < 50) { 
     2037                                        $all_criterias = array ("TO","SUBJECT","FROM","CC"); 
     2038                                        foreach($all_criterias as $criteria_fixed) 
     2039                                        { 
     2040                                                $filter = $criteria_fixed . ' "' . $criteria[1] . '"'; 
     2041                                                $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 
     2042                                                 
     2043                                                if($search_criteria && count($search_criteria) < 50) 
     2044                                                { 
    19332045                                                        foreach($search_criteria as $new_search){ 
    1934                                                                 $m_token = trim("##".$name_box . "--" . $this->get_msg($new_search,$name_box) . "--".$new_search."##"."\n"); 
    1935                                                                 if(!strstr($retorno,$m_token)) 
     2046                                                                $m_token = trim("##".$name_box . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 
     2047                                                                if(!@strstr($retorno,$m_token)) 
    19362048                                                                        $retorno .= $m_token; 
    19372049                                                        } 
     
    19402052                                                        return "many results";                                           
    19412053                                        } 
    1942                                 }                                
     2054                                } 
    19432055                                else { 
    1944                                         $search_criteria = imap_search($mbox_stream,$criteria[0]."\"".$criteria[1]."\"", SE_UID);                                                
     2056                                        $filter = $criteria[0] . '"' . $criteria[1] . '"'; 
     2057                                        $search_criteria = imap_search($mbox_stream, $filter, SE_UID); 
     2058                                                                                         
    19452059                                        if($search_criteria) { 
    19462060                                                foreach($search_criteria as $new_search){ 
    1947                                                         $retorno .= trim("##".$name_box . "--" . $this->get_msg($new_search,$name_box) . "--".$new_search."##"."\n"); 
     2061                                                        $retorno .= trim("##".$name_box . "--" . $this->get_msg($new_search,$name_box,$mbox_stream) . "--".$new_search."##"."\n"); 
    19482062                                                } 
    19492063                                        } 
    19502064                                } 
    1951                                 if($mbox_stream) 
    1952                                         imap_close($mbox_stream);                
    1953                         } 
    1954                 }                
     2065                        } 
     2066                } 
     2067                if($mbox_stream) 
     2068                        imap_close($mbox_stream);                
     2069                                                 
    19552070                return $retorno ? $retorno : "none"; 
    19562071        } 
    19572072         
    1958         function get_msg($uid_msg,$name_box){            
    1959                 $mbox_stream = $this->open_mbox($name_box); 
    1960                 $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255);           
     2073        function get_msg($uid_msg,$name_box, $mbox_stream ) 
     2074        { 
     2075                $header = @imap_headerinfo($mbox_stream, imap_msgno($mbox_stream, $uid_msg), 80, 255);          
    19612076                $subject = $this->decode_string($header->fetchsubject); 
    19622077                $from = $header->from[0]->mailbox; 
     
    19642079                        $from = $header->from[0]->personal; 
    19652080                $ret_msg = $this->decode_string($from) . "--" . $subject . "--". date("d/m/Y",$header ->udate)."--". $this->size_msg($header->Size); 
    1966                 return $ret_msg;                                         
    1967         } 
    1968  
     2081                return $ret_msg;                     
     2082        }        
     2083         
    19692084        function size_msg($size){ 
    19702085                $var = floor($size/1024); 
Note: See TracChangeset for help on using the changeset viewer.