Ticket #843: prognus_r382.diff

File prognus_r382.diff, 7.8 KB (added by wmerlotto, 13 years ago)

Patch1 de correção de anexos em rascunhos

  • expresso/trunk/expressoMail1_2/inc/class.imap_functions.inc.php

     
    27272727        function save_msg($params) 
    27282728        { 
    2729                  
    27302729                include_once("class.phpmailer.php"); 
    27312730                $mail = new PHPMailer(); 
    27322731                include_once("class.db_functions.inc.php"); 
    2733                 $toaddress = $params['input_to']; 
    2734                 $ccaddress = $params['input_cc']; 
    2735                 $subject = $params['input_subject']; 
    2736                 $msg_uid = $params['msg_id']; 
    2737                 $body = $params['body']; 
    2738                 $body = str_replace("%nbsp;"," ",$params['body']); 
     2732                $toaddress    = $params['input_to']; 
     2733                $ccaddress    = $params['input_cc']; 
     2734                $subject      = $params['input_subject']; 
     2735                $msg_uid      = $params['msg_id']; 
     2736                $body         = $params['body']; 
     2737                $body = str_replace("%nbsp;"," ",$body); 
    27392738                $body = preg_replace("/\n/"," ",$body); 
    27402739                $body = preg_replace("/\r/","",$body); 
    27412740                $forwarding_attachments = $params['forwarding_attachments']; 
    2742                 $attachments = $params['FILES']; 
     2741                $attachments  = $params['FILES']; 
    27432742                $return_files = $params['FILES']; 
    27442743 
     
    27742773                $return_forward = $this->buildEmbeddedImages($mail,$msg_uid,$forwarding_attachments); 
    27752774         
    2776                 //Build Forwarding Attachments!!!                
    2777                 if (count($forwarding_attachments) > 0) 
    2778                 { 
    2779                         foreach($forwarding_attachments as $forwarding_attachment) 
    2780                         { 
    2781                                 $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    2782                                 $tmp = array_values($file_description); 
    2783                                 foreach($file_description as $i => $descriptor){                                 
    2784                                         $tmp[$i]  = eregi_replace('\'*\'','',$descriptor); 
    2785                                 } 
    2786                                 $file_description = $tmp; 
    2787                                  
    2788                                 $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
    2789                                 $fileName = $file_description[2]; 
    2790                                  
    2791                                 $file_description[5] = strlen($fileContent); //Size of file 
    2792                                 $return_forward[] = $file_description; 
     2775                //Build Forwarding Attachments!!!        
     2776                foreach($forwarding_attachments as $forwarding_attachment) 
     2777                { 
     2778                        $file_description = unserialize(rawurldecode($forwarding_attachment)); 
    27932779                         
    2794                                         $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
    2795                         } 
     2780                        $file_description = array_values($file_description); 
     2781                        foreach($file_description as $i => $descriptor){                                 
     2782                                $file_description[$i] = eregi_replace('\'*\'','',$descriptor); 
     2783                        } 
     2784                        $fileContent = $this->get_forwarding_attachment($file_description[0], $file_description[1], $file_description[3],$file_description[4]); 
     2785                        $fileName = $file_description[2]; 
     2786                         
     2787                        $file_description[5] = strlen($fileContent); //Size of file 
     2788                        $return_forward[] = $file_description; 
     2789                 
     2790                        $mail->AddStringAttachment($fileContent, $fileName, $file_description[4], $this->get_file_type($file_description[2])); 
    27962791                } 
    27972792                 
    27982793                if ((count($return_forward) > 0) && (count($return_files) > 0)) 
     2794                { 
    27992795                        $return_files = array_merge_recursive($return_forward,$return_files); 
    2800                 else 
    2801                         if (count($return_files) < 1) 
    2802                                 $return_files = $return_forward; 
    2803          
     2796                } 
     2797                else if (count($return_files) < 1) 
     2798                { 
     2799                        $return_files = $return_forward; 
     2800                } 
     2801                 
    28042802                //      Build Uploading Attachments!!! 
    28052803                $sizeof_attachments = count($attachments); 
    28062804                if ($sizeof_attachments) 
    2807                         foreach ($attachments as $numb => $attach){ 
    2808                                 if ($numb == ($sizeof_attachments-1) && $params['insertImg'] == 'true'){ // Auto-resize image 
     2805                { 
     2806                        foreach ($attachments as $numb => $attach) 
     2807                        { 
     2808                                if ($numb == ($sizeof_attachments-1) && $params['insertImg'] == 'true') 
     2809                                { // Auto-resize image 
    28092810                                        list($width, $height,$image_type) = getimagesize($attach['tmp_name']); 
    28102811                                        switch ($image_type) 
    28112812                                        { 
    2812                                         // Do not corrupt animated gif 
    2813                                         //case 1: $image_big = imagecreatefromgif($attach['tmp_name']);break; 
    2814                                         case 2: $image_big = imagecreatefromjpeg($attach['tmp_name']);  break; 
    2815                                         case 3: $image_big = imagecreatefrompng($attach['tmp_name']); break; 
    2816                                         case 6: 
    2817                                                 require_once("gd_functions.php"); 
    2818                                                 $image_big = imagecreatefrombmp($attach['tmp_name']); break; 
    2819                                         default: 
    2820                                                 $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 
    2821                                                 break; 
     2813                                                // Do not corrupt animated gif 
     2814                                                //case 1: $image_big = imagecreatefromgif($attach['tmp_name']);break; 
     2815                                                case 2:  
     2816                                                        $image_big = imagecreatefromjpeg($attach['tmp_name']);  break; 
     2817                                                case 3:  
     2818                                                        $image_big = imagecreatefrompng($attach['tmp_name']); break; 
     2819                                                case 6: 
     2820                                                        require_once("gd_functions.php"); 
     2821                                                        $image_big = imagecreatefrombmp($attach['tmp_name']); break; 
     2822                                                default: 
     2823                                                        $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 
     2824                                                        break; 
    28222825                                        } 
    28232826                                        header('Content-type: image/jpeg'); 
    28242827                                        $max_resolution = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['image_size']; 
    28252828                                        $max_resolution = ($max_resolution==""?'65536':$max_resolution); 
    2826                                         if ($width < $max_resolution && $height < $max_resolution){ 
     2829                                        if ($width < $max_resolution && $height < $max_resolution) 
     2830                                        { 
    28272831                                                $new_width = $width; 
    28282832                                                $new_height = $height; 
    28292833                                        } 
    2830                                         else if ($width > $max_resolution){ 
     2834                                        else if ($width > $max_resolution) 
     2835                                        { 
    28312836                                                $new_width = $max_resolution; 
    28322837                                                $new_height = $height*($new_width/$width); 
    28332838                                        } 
    2834                                         else { 
     2839                                        else  
     2840                                        { 
    28352841                                                $new_height = $max_resolution; 
    28362842                                                $new_width = $width*($new_height/$height); 
     
    28442850                                } 
    28452851                                else 
     2852                                { 
    28462853                                        $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $this->get_file_type($attach['name'])); 
    2847                                 // optional name 
    2848                                 } 
    2849          
    2850          
    2851          
     2854                                        // optional name 
     2855                                } 
     2856                        } 
     2857                } 
    28522858                 
    28532859                if(!empty($mail->AltBody)) 
     
    28572863                $mail->SetMessageType(); 
    28582864                $header = $mail->CreateHeader(); 
    2859                 $body = $mail->CreateBody();  
     2865                $body   = $mail->CreateBody();  
    28602866 
    28612867                $mbox_stream = $this->open_mbox($folder);        
    2862                 $new_header = str_replace("\n", "\r\n", $header); 
    2863                 $new_body = str_replace("\n", "\r\n", $body); 
     2868                $new_header  = str_replace("\n", "\r\n", $header); 
     2869                $new_body    = str_replace("\n", "\r\n", $body); 
    28642870                $return['append'] = imap_append($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, $new_header . $new_body, "\\Seen \\Draft"); 
    2865                 $status = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
     2871                $status      = imap_status($mbox_stream, "{".$this->imap_server.":".$this->imap_port."}".$folder, SA_UIDNEXT); 
    28662872                $return['msg_no'] = $status->uidnext - 1; 
    28672873                $return['folder_id'] = $folder; 
     
    28692875                if($mbox_stream) 
    28702876                        imap_close($mbox_stream); 
    2871                 if (is_array($return_files))               
    2872                         foreach ($return_files as $index => $_attachment) { 
    2873                                 if (array_key_exists("name",$_attachment)){ 
    2874                                 unset($return_files[$index]); 
    2875                                 $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; 
    2876                         } 
    2877                         else 
    2878                         { 
    2879                                 unset($return_files[$index]); 
    2880                                 $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; 
     2877                         
     2878                if (is_array($return_files)) 
     2879                { 
     2880                        foreach ($return_files as $index => $_attachment)  
     2881                        { 
     2882                                if (array_key_exists("name", $_attachment)) 
     2883                                { 
     2884                                        //unset($return_files[$index]); 
     2885                                        $return_files[$index] = $_attachment['name']."_SIZE_".$return_files[$index][1] = $_attachment['size']; 
     2886                                } 
     2887                                else 
     2888                                { 
     2889                                        //unset($return_files[$index]); 
     2890                                        $return_files[$index] = $_attachment[2]."_SIZE_". $return_files[$index][1] = $_attachment[5]; 
     2891                                } 
    28812892                        } 
    28822893                }