Ignore:
Timestamp:
12/20/10 15:05:48 (13 years ago)
Author:
eduardoalex
Message:

Ticket #1408 - Adição de envio de anexos, normal e no forward

Location:
branches/2.2/mobile/inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/mobile/inc/class.common_functions.inc.php

    r3573 r3609  
    6363                } 
    6464                 
     65                /** 
     66                 * Fixes the odd indexing of multiple file uploads from the format: 
     67                 * 
     68                 * $_FILES['field']['key']['index'] 
     69                 * 
     70                 * To the more standard and appropriate: 
     71                 * 
     72                 * $_FILES['field']['index']['key'] 
     73                 * 
     74                 * @param array $files 
     75                 * @author Corey Ballou 
     76                 * @link http://www.jqueryin.com 
     77                 */ 
     78                function fixFilesArray(&$files) 
     79                { 
     80                    $names = array( 'name' => 1, 'type' => 1, 'tmp_name' => 1, 'error' => 1, 'size' => 1); 
     81                 
     82                    foreach ($files as $key => $part) { 
     83                        // only deal with valid keys and multiple files 
     84                        $key = (string) $key; 
     85                        if (isset($names[$key]) && is_array($part)) { 
     86                            foreach ($part as $position => $value) { 
     87                                $files[$position][$key] = $value; 
     88                            } 
     89                            // remove old key reference 
     90                            unset($files[$key]); 
     91                        } 
     92                    } 
     93                } 
     94                 
    6595        } //end common class 
    6696         
  • branches/2.2/mobile/inc/class.ui_mobilemail.inc.php

    r3605 r3609  
    322322                    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] = $current_config['expressoMail_command_for_spam']; 
    323323                    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_use_spam_filter'] = $current_config['expressoMail_use_spam_filter']; 
     324                        $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size'] = $current_config['expressoMail_Max_attachment_size'] ? $current_config['expressoMail_Max_attachment_size']."M" : ini_get('upload_max_filesize'); 
    324325 
    325326                        // echo '<script> var array_lang = new Array();var use_spam_filter = \''.$current_config['expressoMail_use_spam_filter'].'\' </script>'; 
     
    418419                {        
    419420                                 
    420                         $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); 
     421                        $p = $this->template; 
    421422                        $p->set_file( 
    422423                                Array( 
     
    475476                { 
    476477                         
    477                         $functions = CreateObject('mobile.common_functions'); 
    478                         $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); 
     478                        $functions = $this->common; 
     479                        $p = $this->template; 
    479480                                        $p->set_file( 
    480481                                                Array( 
     
    542543                        } 
    543544                        return $p->fp('out','rows_mails'); 
    544 /* 
    545                         // Cria a lista de e-mails 
    546                         $mail_rows = ''; 
    547       $unread_msg_count = 0; 
    548        
    549                         if ($this->number_of_messages != 0) 
    550                         { 
    551                                 $unread_msg_count = 0; 
    552                                 foreach ($messages as $index => $msg) 
    553                                 { 
    554                                   $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); 
    555                                         $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); 
    556                                         $p->set_block('mobilemail_t', 'mail_row'); 
    557                                         $p->set_block('mobilemail_t', 'end_strong'); 
    558                                         $p->set_block('mobilemail_t', 'begin_strong'); 
    559                                         $p->set_var('unseen_bkg', "seen_bkg"); 
    560                                         $p->set_var('itememail_access_key', "0"); 
    561                                         $p->set_var('str_new_message', ""); 
    562  
    563                                         if (is_numeric($index)) 
    564                                         { 
    565                                                 !empty($msg['from']['name']) ? $from = $msg['from']['name'] : $from = $msg['from']['email']; 
    566                                                 !empty($msg['subject']) ? $subject = $msg['subject'] : $subject = lang('[empty subject]'); 
    567                                                 if ($msg['Unseen'] == 'U') 
    568                                                 { //Setando as mensagens nao lidas 
    569                                                         $p->set_var('strong_unseen_begin', trim($p->fp('mobilemail_t', 'begin_strong'))); 
    570                                                         $p->set_var('strong_unseen_end', trim($p->fp('mobilemail_t', 'end_strong'))); 
    571                                                         $p->set_var('unseen_bkg', "unseen_bkg"); 
    572                                                         $p->set_var('itememail_access_key', "9"); 
    573                                                         $unread_msg_count = $unread_msg_count + 1; 
    574                                                         $p->set_var('str_new_message', lang("New message")); 
    575                                                 } 
    576                                                 $p->set_var('from', $from); 
    577                                                 $p->set_var('subject', $subject); 
    578                                                 $p->set_var('msg_number', $msg['msg_number']); 
    579                                                 $p->set_var('date', $msg['smalldate']); 
    580                                                 $p->set_var('msg_folder', $this->folders[$this->current_folder]['folder_id']); 
    581                                                 $p->set_var('from_label', lang('From')); 
    582                                                 $mail_rows .= $p->fp('mobilemail_t', 'mail_row'); 
    583                                         } 
    584                                 } 
    585      
    586                                 // Imprime a lista de e-mails 
    587                                 $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); 
    588                                 $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); 
    589                                 $p->set_block('mobilemail_t', 'mail_list'); 
    590                                 $p->set_var('mail_rows', $mail_rows); 
    591                                 $p->set_var('messages_total', $this->number_of_messages); 
    592                                 $p->set_var('unread_messages_total', $unread_msg_count); 
    593                                 if ($unread_msg_count) 
    594                                 { 
    595                                         $p->set_var('(unread_messages_total)', '('.$unread_msg_count.')'); 
    596                                 } 
    597                                  
    598                                 //$p->pfp('out', 'mail_list'); 
    599                                 $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_list')); 
    600                         } 
    601                         else 
    602                         { 
    603                                 // Lista de e-mails vazia 
    604                                 $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']); 
    605                                 $p->set_file(array('mobilemail_t' => 'mobilemail.tpl')); 
    606                                 $p->set_block('mobilemail_t', 'empty_list'); 
    607                                 $p->set_var('empty_message', lang('Empty folder'));                              
    608                                 //$p->pfp('out', 'empty_list'); 
    609                                 $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'empty_list')); 
    610                         }*/ 
     545 
    611546                } 
    612547 
     
    753688                        $this->template->set_var('lang_read_confirmation', lang("read confirmation")); 
    754689                        $this->template->set_var('lang_add_history', lang("add history")); 
     690                        $this->template->set_var("show_forward_attachment","none"); 
    755691                         
    756692                        if(isset($params["error_message"])) { 
     
    772708                                if (isset($params['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $params['msg_number'], 'msg_folder' => $params['msg_folder'] ) ); 
    773709                                 
     710                                 
    774711                                if($params['type']=="clk") 
    775712                                { 
     
    830767                                         
    831768                                        $this->template->set_var('msg_number', $_GET['msg_number']); 
    832                                         $this->template->set_var('msg_folder', $_GET['msg_folder']);             
     769                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);     
     770                                        if(count($msg['attachments'])>0) { 
     771                                                $this->template->set_var("lang_forward_attachment",lang("forward attachments")); 
     772                                                $this->template->set_var("show_forward_attachment","block"); 
     773                                                $this->template->set_block("new_msg_t","forward_attach_block"); 
     774                                                foreach($msg['attachments'] as $forward_attach) { 
     775                                                        $value = rawurlencode(serialize(array(0=>$msg['msg_folder'], 
     776                                                                                   1=>$msg['msg_number'], 
     777                                                                                   3=>$forward_attach['pid'], 
     778                                                                                   2=>$forward_attach['name'], 
     779                                                                                   4=>$forward_attach['encoding']))); 
     780                                                        $this->template->set_var("value_forward_attach",$value); 
     781                                                        $this->template->set_var("label_forward_attach",$forward_attach['name']); 
     782                                                        $this->template->fp("forwarding_attachments","forward_attach_block",true); 
     783                                                } 
     784                                        } 
     785                                                 
    833786                                } 
    834787                                else if($params['type']=="use_draft"){ 
     
    838791                                        $this->template->set_var('body_value', strip_tags($msg['body'])); // Usa a função strip_tags() para filtrar 
    839792                                        $this->template->set_var('msg_number', $_GET['msg_number']); 
    840                                         $this->template->set_var('msg_folder', $_GET['msg_folder']);             
     793                                        $this->template->set_var('msg_folder', $_GET['msg_folder']); 
    841794                                } 
    842795                                else{ 
     
    867820                { 
    868821                        $params["folder"] = "INBOX/".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']; 
     822                        $params["FILES"] = $_FILES["FILES"]; 
     823                        $this->common->fixFilesArray($params["FILES"]); 
     824                        $params['forwarding_attachments'] = $params["forward_attachments"]; 
    869825                        $return = $this->imap_functions->save_msg($params); 
    870826                        if($return["has_error"]) { 
     
    885841                        //Chamada da classe phpmailer 
    886842                        include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.phpmailer.php"); 
    887  
     843                        include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.imap_functions.inc.php"); 
     844                         
    888845                        //Recebe os dados do form (passados pelo POST) 
    889846                        $toaddress = $_POST['input_to']; 
    890847                        $ccaddress = $_POST['input_cc']; 
    891848                        $subject = $_POST['input_subject']; //"Mail Subject"; 
    892                         $body = $_POST['body']; //"Mail body. Any text."; 
     849                        $body = nl2br($_POST['body']); //"Mail body. Any text."; 
    893850                        $isImportant = $_POST['check_important']; 
    894851                        $addHistory = $_POST['check_add_history']; 
    895852                        $readConfirmation = $_POST['check_read_confirmation']; 
    896853                        $msgNumber = $_POST['reply_msg_number']; 
     854                        $attachments = $_FILES['FILES']; 
     855                        $this->common->fixFilesArray($attachments); 
     856                        $forwarding_attachments = $_POST["forward_attachments"]; 
     857                         
    897858 
    898859                        //Cria objeto 
     
    940901                        if ($readConfirmation) $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email']; 
    941902 
     903                        $imap_functions = new imap_functions(); 
     904                        if (count($attachments)>0) //Attachment 
     905                        { 
     906                                 
     907                                $total_uploaded_size = 0; 
     908                                $upload_max_filesize = str_replace("M","",$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024; 
     909                                 
     910                                foreach ($attachments as $attach) 
     911                                { 
     912                                        $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $imap_functions->get_file_type($attach['name']));  // optional name                                         
     913                                        $total_uploaded_size = $total_uploaded_size + $attach['size']; 
     914                                } 
     915                                if( $total_uploaded_size > $upload_max_filesize){ 
     916 
     917                                        return $imap_functions->parse_error("message file too big"); 
     918                                } 
     919                        } 
     920                        if (count($forwarding_attachments) > 0) { //forward attachment 
     921                                foreach($forwarding_attachments as $forwarding_attachment) 
     922                                { 
     923                                        $file_description = unserialize(rawurldecode($forwarding_attachment)); 
     924                                        $fileContent = $imap_functions->get_forwarding_attachment( 
     925                                                                                        $file_description[0], 
     926                                                                                        $file_description[1], 
     927                                                                                        $file_description[3], 
     928                                                                                        $file_description[4]); 
     929                                        $fileName = $file_description[2]; 
     930                                        $mail->AddStringAttachment($fileContent,html_entity_decode(rawurldecode($fileName)), $file_description[4], $imap_functions->get_file_type($file_description[2])); 
     931 
     932                                } 
     933                        } 
     934                         
    942935                        //Se o e-mail nao for enviado por qualquer motivo... 
    943936                        if(!$mail->Send()) { 
Note: See TracChangeset for help on using the changeset viewer.