source: branches/2.2/mobile/inc/class.ui_mobilemail.inc.php @ 4002

Revision 4002, 45.0 KB checked in by thiagoaos, 13 years ago (diff)

Ticket #1747 - Traduzido o nome das pastas padrões no mobile.

  • Property svn:executable set to *
RevLine 
[623]1<?php
2        /**************************************************************************\
3        * eGroupWare                                                               *
4        * http://www.egroupware.org                                                *
5        * The file written by Mário César Kolling <mario.kolling@serpro.gov.br>    *
6        * --------------------------------------------                             *
7        *  This program is free software; you can redistribute it and/or modify it *
8        *  under the terms of the GNU General Public License as published by the   *
9        *  Free Software Foundation; either version 2 of the License, or (at your  *
10        *  option) any later version.                                              *
11        \**************************************************************************/
12
13        //TODO: Criar a Classe Widget.
14
15        include_once(PHPGW_INCLUDE_ROOT.'/expressoMail1_2/inc/class.imap_functions.inc.php');
16
17        // Classe principal do Mini Mail
18        class ui_mobilemail{
19
20                // Define as funções públicas
21                var $public_functions = array(
22                        'mail_list'     => True,
23                        'change_folder' => True,
24                        'change_page'   => True,
25                        'show_msg'      => True,
26                        'send_mail'     => True,
27                        //'reply_msg'   => True,
28                        'new_msg'       => True,
[1453]29                        'delete_msg'    => True,
30                        'confirm_delete_msg'    => True,
[1474]31                        'init_schedule' => true,
32                        'add_recipients' => true,
33                        'add_recipient' => true,
[3571]34                        'list_folders' => true,
[3576]35                        'save_draft' => true,
[3579]36                        'mark_message_with_flag' => true,
[3589]37                        'change_search_box_type' => true,
38                        'index' => true
[623]39                );
[4002]40       
41                var $bo_mobilemail;
[3571]42                var $template;
[3576]43                var $common;
[623]44                var $folders; // Pastas imap
[3579]45                var $current_search_box_type;
[623]46                var $current_folder; // Pasta corrente
47                var $current_page; // Página corrente da lista de e-mails da pasta corrente
48                var $imap_functions; // Variável que recebe um objeto do tipo class.imap_functions.inc.php
49                var $allowed_tags = '<p><a><br><em><strong><ol><li><ul><div><font>'; // Tags html que não serão removidas
50                        // ao mostrar corpo do e-mail
51
52
53                /*
54                 * @function mobilemail
55                 * @abstract Método construtor da classe principal do Mini Mail
56                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
57                 */
58                function ui_mobilemail()
59                {
[4002]60                        $this-> load_session();
[3571]61                        $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
[3576]62                        $this->common   = CreateObject('mobile.common_functions');
[4002]63                        $this->bo_mobilemail = CreateObject('mobile.bo_mobilemail');
[3571]64                       
[623]65                        // Recupera atributos da classe gravados na sessão
66                        $folders = $GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile');
67                        $current_folder = $GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile');
68                        $current_page = $GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile');
[3579]69                        $current_search_box_type = $GLOBALS['phpgw']->session->appsession('mobilemail.current_search_box_type','mobile');
70                       
[623]71                        // Inicializa a classe class.imap_functions.inc.php
72                        $this->imap_functions = new imap_functions();
73
74                        // Testa a existência dos atributos da classe recuperadas da sessão, e as carrega ou inicializa.
75                        if ($folders)
76                        {
77                                $this->folders = $folders;
78                        }
79                        else
80                        {
[1848]81                                $this->folders = $this->imap_functions->get_folders_list(array('noSharedFolders' => true));
[623]82                        }
83
84                        if ($current_folder)
85                        {
86                                $this->current_folder = $current_folder;
[3346]87                                $current_page = 1;
[623]88                        }
89                        else
90                        {
91                                $this->current_folder = 0; // Define o folder INBOX como o folder corrente
92                        }
93
94                        if ($current_page)
95                        {
96                                $this->current_page = $current_page;
97                        }
98                        else
99                        {
100                                $this->current_page = 1; // Define a primeira página como página padrão
101                        }
[3579]102                       
103                        if($current_search_box_type)
104                        {
105                                $this->current_search_box_type = $current_search_box_type;
106                        }
107                        else {
108                                $this->current_search_box_type = "all";
109                        }
[623]110
111                }
112
113                /*
114                 * @function save_session
115                 * @abstract Salva os atributos da classe na sessão
116                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
117                 */
118                function save_session()
119                {
120                        $GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile',$this->folders);
121                        $GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile',$this->current_folder);
122                        $GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile',$this->current_page);
[3579]123                        $GLOBALS['phpgw']->session->appsession('mobilemail.current_search_box_type','mobile',$this->current_search_box_type);
[623]124                }
125
126                /*
127                 * @function change_page
128                 * @abstract Troca a página de exibição da lista de e-mails, e mostra a nova página
129                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
130                 */
[3579]131                function change_page($params)
[623]132                {
[3579]133                        if (isset($params['page']))
[623]134                        {
[3579]135                                $this->current_page = $params['page'];
[623]136                        }
137                        $this->mail_list();
138                        $this->save_session();
139                }
140
[3579]141                function change_search_box_type($params) {
142                        if (isset($params['search_box_type']))
143                        {
144                                $this->current_search_box_type = $params['search_box_type'];
145                                $this->current_page = 1;
146                        }
147                        $this->mail_list();
148                        $this->save_session();
149                }
150
[623]151                /*
152                 * @function change_folder
153                 * @abstract Troca a pasta do imap, e mostra a primeira página da nova pasta
154                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
155                 */
[3576]156                function change_folder($params)
[623]157                {
[3576]158                        $folder = $params['folder'];
[623]159                        if (isset($folder))
160                        {
161                                $this->current_folder = $folder;
162                                $this->current_page = 1;
[3579]163                                $this->current_search_box_type = "all";
[623]164                        }
[3576]165                       
[3579]166                               
[3576]167                        $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
[3589]168                        $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]);
[3579]169                        $this->mail_list();
[623]170                        $this->save_session();
171                }
[3576]172               
173                function mark_message_with_flag($params=array())
174                {
[3589]175                       
[3655]176                        if(isset($params['msgs']))
[3589]177                                $params["msgs_to_set"] = implode(",",$params["msgs"]);
178                       
[3655]179                        if (isset($params["msgs_to_set"])){
[3576]180                       
[3655]181                                $return = $this->imap_functions->set_messages_flag($params);
[3576]182                       
[3655]183                                if($return)
184                                        header('Location: index.php?menuaction=menuaction=mobile.ui_mobilemail.index&success_message='.lang("The messages were marked as seen"));
185                                else
186                                        header('Location: index.php?menuaction=menuaction=mobile.ui_mobilemail.show_msg&msg_number='.$params["msgs_to_set"].'&msg_folder='.$return["msg_folder"].'&error_message='.$return["msg"]);
187                                       
188                        } else {
[3658]189                                header('Location: index.php?menuaction=menuaction=mobile.ui_mobilemail.index&error_message='.lang("please select one e-mail"));
[3655]190                        }
191                       
[3576]192                        exit;
193                }
194               
[623]195                /*
196                 * @function show_msg
197                 * @abstract Mostra a mensagem de e-mail requisitada
198                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
199                 */
200                 // TODO: retirar msg_folder dos parâmentros necessários no GET e usar $this->current_folder
[3576]201                function show_msg($params = array())
[623]202                {
203                        $msg = $this->imap_functions->get_info_msg($params);
204
[3602]205                        $msg_number = $params['msg_number'];
206                        $msg_folder = $params['msg_folder'];
207
[623]208                        // Carrega o template
[3576]209                        $this->template->set_file(array('view_msg' => 'view_msg.tpl'));
210                        $this->template->set_block('view_msg', 'page');
[3602]211                        $this->template->set_block('view_msg', 'operation_block');
[3697]212                        $this->template->set_block('view_msg', 'attachment_alert_block');
[3576]213                        $this->template->set_var('lang_back', lang("back"));
[3829]214                        $this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
[3576]215                        $this->template->set_var('lang_reading_message', lang("Reading Message"));
[3697]216                        $this->template->set_var('theme', $GLOBALS['phpgw_info']['server']['template_set']);
[623]217
218                        // Define o cabeçalho do e-mail
[3576]219                        $this->template->set_var('lang_from', lang("From"));
[3571]220                        $this->template->set_var('from', $msg['from']['full']);
[3697]221                        $this->template->set_var('lang_to', lang("To"));
222                        $this->template->set_var('to', $msg['toaddress2']);
[3576]223                        $this->template->set_var('lang_cc', lang("cc"));
224                        $this->template->set_var('cc', $msg['cc']);
225                        $this->template->set_var('size', $this->common->borkb($msg['Size']));
[623]226
[3576]227                        $this->template->set_var('lang_subject', lang("Subject"));
[3571]228                        $this->template->set_var('subject', $msg['subject']);
[3576]229                        $this->template->set_var('date', $msg['msg_day']." ".$msg['msg_hour']);
[623]230
231                        // Mostra o corpo do e-mail
[3571]232                        $this->template->set_var('body', strip_tags($msg['body'], $this->allowed_tags)); // Usa a função strip_tags() para filtrar
[3907]233
[3602]234                        $operations = array();
[3907]235
[3602]236                        if($msg["Draft"] === "X") {
237                                $operations["edit_draft"]["link"] = "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=use_draft";
238                                $operations["edit_draft"]["lang"] = lang("edit draft");
239                        }       else {
240                                $operations["mark_as_unread"]["link"] = "index.php?menuaction=mobile.ui_mobilemail.mark_message_with_flag&flag=unseen&msgs_to_set=$msg_number&msg_folder=$msg_folder";
241                                $operations["mark_as_unread"]["lang"] = lang("mark as unread");
242                                $operations["forward"]["link"] = "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=forward";
243                                $operations["forward"]["lang"] = lang("Forward");
[3935]244                                $operations["reply"]["link"] = "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=reply";
[3602]245                                $operations["reply"]["lang"] = lang("Reply");
246                                $operations["reply_all"]["link"] = "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=reply_all";
247                                $operations["reply_all"]["lang"] = lang("Reply to all");
248                        }
[3907]249
[3602]250                        $operations["delete"]["link"] = "index.php?menuaction=mobile.ui_mobilemail.confirm_delete_msg&msg_number=$msg_number&msg_folder=$msg_folder";
[3907]251                        $operations["delete"]["lang"] = lang("Delete");
252
[3602]253                        foreach($operations as $index=>$operation) {
254                                $this->template->set_var('operation_link', $operation["link"]);
255                                $this->template->set_var('operation_id', $index);
[3907]256                                $this->template->set_var('lang_operation', $operation["lang"]);
257                                $this->template->parse('operation_box','operation_block', true);
[3602]258                        }
[3907]259
[3289]260                        if (!empty($msg['attachments']))
[623]261                        {
[691]262                                $attachs = "<br>".lang("This message has the follow attachments:")."<br>";
263                                foreach($msg['attachments'] as $key => $attach) {
264                                        if(is_array($attach)) {
[3501]265                                                //$attachs.=$attach['name']."&nbsp;&nbsp;&nbsp;&nbsp;";
266                                                $attachs.="<a href='../expressoMail1_2/inc/gotodownload.php?msg_folder=".$msg_folder.
267                                                                  "&msg_number=".$msg_number."&idx_file=".$key."&msg_part=".$attach['pid'].
268                                                                  "&newfilename=".$attach['name']."&encoding=".$attach['encoding']."'>".
269                                                                          lang('Download').":&nbsp;".$attach['name']."</a><br>";
[691]270                                        }
271                                }
[3907]272
[3697]273                                $this->template->parse('attachment_alert_box','attachment_alert_block', true);
[3576]274                                $this->template->set_var('attachment_message', $attachs);
[623]275                        }
276                        else
277                        {
[3571]278                                $this->template->set_var('attachment_message', lang('This message don\'t have attachment(s)'));
[623]279                        }
280
[3576]281                        $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
282                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page'));
[623]283                }
284
285                /*
286                 * @function index
287                 * @abstract Página inicial da aplicação mobilemail, mantém o estado atual. Ou seja, mostra lista de e-mails
288                 * do folder e página definidos pelos parâmetros current_folder e current_page.
289                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
290                 */
291                 // TODO: Talvez seja melhor voltar sempre para o Inbox e primeira página
[3589]292                function index($params)
[1474]293                {
[3589]294                        $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
295                        $GLOBALS['phpgw_info']['mobiletemplate']->set_success_msg($params["success_message"]);
[623]296                        $this->mail_list();
297                        $this->save_session();
298
299                }
300               
[1474]301                function load_session(){
[623]302                        /************************************\
303                         * Inicialização do expressoMail1_2 *
304                        \************************************/
305                        // Get Data from ldap_manager and emailadmin.
306                        $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
307                        $boemailadmin   = CreateObject('emailadmin.bo');
308                        $emailadmin_profile = $boemailadmin->getProfileList();
309                        $_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
310                        $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
311                        $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
312                        $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
313                        $_SESSION['phpgw_info']['expressomail']['user']['email'] = $GLOBALS['phpgw']->preferences->values['email'];
314               
315                        // Fix problem with cyrus delimiter changes in preferences.
316                        // Dots in names: enabled/disabled.
317                        $save_in_folder = @eregi_replace("INBOX/", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']);
318                        $save_in_folder = @eregi_replace("INBOX.", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $save_in_folder);
319                        $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'] = $save_in_folder;
320                        // End Fix.
321               
322                    // Loading Admin Config Module
323                    $c = CreateObject('phpgwapi.config','expressoMail1_2');
324                    $c->read_repository();
325                    $current_config = $c->config_data;
326                    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] = $current_config['expressoMail_enable_log_messages'];
327                    // Begin Set Anti-Spam options.
328                    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] = $current_config['expressoMail_command_for_ham'];
329                    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] = $current_config['expressoMail_command_for_spam'];
330                    $_SESSION['phpgw_info']['server']['expressomail']['expressoMail_use_spam_filter'] = $current_config['expressoMail_use_spam_filter'];
[3609]331                        $_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');
[691]332
[3576]333                        // echo '<script> var array_lang = new Array();var use_spam_filter = \''.$current_config['expressoMail_use_spam_filter'].'\' </script>';
[691]334
[623]335                        // End Set Anti-Spam options.
336               
337                    // Set Imap Folder names options
338                    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']   = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']     ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder']             : "Trash";
339                    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']  = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder']       : "Drafts";
340                    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']    = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']      ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder']              : "Spam";
341                    $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']    = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']      ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder']              : "Sent";
[691]342
[3576]343                        // include("../expressoMail1_2/inc/load_lang.php");                 
[623]344                }
345
346                /*
347                 * @function print_folder_selection
348                 * @abstract Imprime o folder corrente (INBOX)
349                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
350                 */
351                function print_folder_selection()
352                {
[3571]353                        $this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
354                        $this->template->set_block('mobilemail_t', 'inbox_folder_list');
355                        $this->template->set_var('lang_folder', lang('Folder'));
[1714]356                        $folder = str_replace("*","",lang($this->folders[$this->current_folder]['folder_name']));
[1474]357                        if(!$this->current_folder == 0){
[3571]358                                $this->template->set_var('lang_inbox', $folder.' :: <a title="'.lang('Inbox').'" href="index.php?menuaction=mobile.ui_mobilemail.mail_list&folder=0">'.lang('Inbox').'</a>');
[1474]359                        }else{
[3571]360                                $this->template->set_var('lang_inbox', lang('Inbox'));
[1474]361                        }
362                       
[3571]363                        //$this->template->set_var('folder_items', $folder_items);
364                        $this->template->parse('mobilemail_t', 'inbox_folder_list');                   
365                        //$this->template->fpf('out', 'mobilemail_t');
366                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'mobilemail_t'));
[623]367                }
368
369                /*
370                 * @function old_print_folder_selection
371                 * @abstract Imprime na tela a caixa de seleção de folders
372                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
373                 */
374                function old_print_folder_selection()
375                {
376                        // Processa as options
377                        $folder_items = '';
378
379                        foreach ($this->folders as $i => $j)
380                        {
381
382                                $option_selected = '';
[3571]383                                $this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
384                                $this->template->set_block('mobilemail_t', 'folder_item');
[623]385
386                                if (is_numeric($i))
387                                {
388                                        if ($i == $this->current_folder)
389                                        {
390                                                 $option_selected = 'selected="selected"';
391                                        }
392
[3571]393                                        $this->template->set_var('option_selected', $option_selected);
394                                        $this->template->set_var('folder_id', $j['folder_id']);
395                                        $this->template->set_var('folder_name', $j['folder_id']); // Mudar... provavelmente usar preg_replace
[4002]396                                        // para substituir cpf pelo nome do usuário.
[623]397                                        if ($j['folder_unseen'] > 0)
[3571]398                                                $this->template->set_var('folder_unseen', ' - ('.$j['folder_unseen'].')');
[623]399
[3571]400                                        $folder_items .= $this->template->fp('mobile_t', 'folder_item');
[623]401                                }
402                        }
403
404                        // Processa o select
[3571]405                        $this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
406                        $this->template->set_block('mobilemail_t', 'folder_list');
407                        $this->template->set_var('folder_items', $folder_items);
408                        $this->template->parse('mobilemail_t', 'folder_list');                 
409                        //$this->template->pfp('out', 'mobilemail_t');
410                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'mobilemail_t'));
[623]411
412                }
413
414                /*
415                 * @function mail_list
416                 * @abstract Imprime a lista de e-mails
417                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
418                 */
[3579]419                function mail_list()
[1474]420                {       
[3579]421                               
[3609]422                        $p = $this->template;
[4002]423                        $p->set_file( array( 'mail_t' => 'mobilemail.tpl', 'home_search_bar' => 'search_bar.tpl' ) );
[3641]424
425                        $p->set_block('home_search_bar','search_bar');
426
[3579]427                        $p->set_var("page",$this->current_page+1);
[3589]428                        $p->set_var("lang_new_message",lang("new message"));
429                        $p->set_var("lang_new",strtoupper(lang("new")));
430                        $p->set_var("folder_id",$this->folders[$this->current_folder]['folder_id']);
[4002]431                        //translate name of the default folders
432                        $translated_folder_name = $this->bo_mobilemail->get_translate_default_folder_name_from_id($this->folders[$this->current_folder]["folder_id"]);
433                        $p->set_var("folder", (($translated_folder_name == "") ? $this->folders[$this->current_folder]["folder_name"] : $translated_folder_name) );
434                       
[3579]435                        $p->set_var("selected_".$this->current_search_box_type,"selected");
436                        $p->set_var("lang_back",lang("back"));
[3829]437                        $p->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
[3691]438                        $p->set_var("selecteds",ucfirst(lang("Selecteds")));
439                        $p->set_var("filter_by",lang("filter by"));
[3579]440                        $p->set_var("lang_new_message",lang("new message"));
[3641]441                        $p->set_var('lang_search',lang('search'));
[3579]442                        $p->set_var("lang_more",lang("more"));
443                        $p->set_var("lang_messages",lang("messages"));
444                       
[3731]445                        if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile')!="mini_desktop")
446                                $p->set_var('search',$p->fp('out','search_bar'));
447                       
[3579]448                        $max_per_page =
[691]449                                        isset($GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page'])?
450                                        $GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page']:10;
[3579]451                                               
452                        $params = array(
453                                'folder'                        => $this->folders[$this->current_folder]['folder_id'],
454                                'msg_range_begin'       => 1,
455                                'msg_range_end'         => $this->current_page * $max_per_page,
456                                'search_box_type'       => $this->current_search_box_type,
457                                'sort_box_type'         => 'SORTARRIVAL',
458                                'sort_box_reverse'      => 1
459                        );
[1709]460                       
[3579]461                        $messages = $this->imap_functions->get_range_msgs2($params);
[3589]462                        if($params['msg_range_end']<$messages[num_msgs])
463                                $p->set_var("show_more","block");
464                        else
465                                $p->set_var("show_more","none");
[3579]466                        $this->number_of_messages = $messages[num_msgs];
467                       
468                        unset($messages["offsetToGMT"]);
469                        unset($messages["tot_unseen"]);
470                       
471                        $p->set_var('mails',$this->print_mails_list($messages,true));
472                       
473                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out','mail_t'));
474                       
[623]475
476                }
477
478                /*
479                 * @function print_mails_list
480                 * @abstract Imprime a lista de mensagens
481                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
482                 * @param array Um array com a lista de mensagens recuperado por $this->imap_functions->get_range_msgs2($params)
483                 */
[3579]484                function print_mails_list($messages,$print_checkbox=false)
[623]485                {
[3573]486                       
[3609]487                        $functions = $this->common;
488                        $p = $this->template;
[3791]489                        $p->set_file( array( 'mobilemail_t' => 'mails_list.tpl' ) );
[3573]490                        $p->set_block('mobilemail_t', 'rows_mails');
491                        $p->set_block('mobilemail_t', 'row_mails');
492                        $p->set_block('mobilemail_t', 'no_messages');
[623]493
[3573]494                        if(count($messages)>1) { //O array de emails tem pelo menos uma posição com o total de mensagens.
[3691]495                                $bg = "bg-azul";
[3573]496                                foreach($messages as $id => $message) {
497                                       
[3923]498                                        if(($id==='num_msgs') ||($id==='total_msgs') || ($id==='has_more_msg'))
[3573]499                                                continue;
500                                        if($message['from']['name'])
[3590]501                                                $from_name = $message['from']['name'];
[3573]502                                        else
[3590]503                                                $from_name = $message['from']['email'];
[3691]504                                        $bg = $bg=="bg-azul"?"bg-branco":"bg-azul";
505                                        $p->set_var('bg',"email-geral $bg");
[3573]506                                       
[3691]507                                        $flag="";
[3589]508                                                                               
[3691]509                                        if($message["Unseen"]==="U")
510                                                $flag="email-nao-lido ";
511                                        else
512                                                $flag="email-lido ";
[3579]513                                       
[3589]514                                        if($message["Flagged"]==="F")
[3691]515                                                $flag.="email-importante";
[3579]516                                       
[3589]517                                        $p->set_var("flag",$flag);
[3579]518                                        if($print_checkbox)
519                                                $p->set_var('show_check','inline');
520                                        else
521                                                $p->set_var('show_check','none');
522                                       
[3691]523                                        if($print_checkbox)
524                                                $p->set_var("details","email-corpo");
525                                        else
526                                                $p->set_var("details","limpar_div margin-geral");
527
[3579]528                                        $p->set_var('pre_type',$pre);
529                                        $p->set_var('pos_type',$pos);
[3573]530                                        $p->set_var('from',$from_name);
[3691]531                                        $p->set_var('url_images','templates/'.$GLOBALS['phpgw_info']['server']['template_set'].'/images');
[3589]532                                        $p->set_var('msg_number',$message["msg_number"]);
[3573]533                                        $p->set_var('mail_time',$message['smalldate']);
[3651]534                                        $p->set_var('mail_from',$message['from']['email']);
[3691]535                                        $p->set_var('subject',$message['subject']?$message['subject']:"(".lang("no subject").")");
[3573]536                                        $p->set_var('size',$functions->borkb($message['Size']));
[3695]537                                        $p->set_var('lang_attachment',lang('attachment'));
[3573]538                                        $p->set_var('msg_number', $message['msg_number']);
[3791]539                                        $p->set_var('msg_folder', isset($message['msg_folder']) ? $message['msg_folder'] : $this->folders[$this->current_folder]['folder_id']);
540                                        $p->set_var('show_attach', ($message['attachment']['number_attachments']>0) ? '' : 'none');
[3573]541                                        $p->fp('rows','row_mails',True);
[623]542                                }
543                        }
[3573]544                        else {
545                                $p->set_var("lang_no_results",lang("no results found"));
546                                $p->parse("rows","no_messages");
[623]547                        }
[3573]548                        return $p->fp('out','rows_mails');
[3579]549
[623]550                }
551
552                /*
553                 * @funtion print_page_navigation
554                 * @abstract Imprime a barra de navegação da lista de e-mails da pasta corrente. Quem chama essa função é quem faz o controle do modelo.
555                 * @author Mário César Kolling <mario.kolling@serpro.gov.br>
556                 * @param integer Número de páginas que serão geradas
557                 * @param integer Página corrente
558                 */
559                // TODO: mover este método para a classe page_navigation subclasse de widget
560                function print_page_navigation($number_of_pages, $page = 1)
561                {
562
563                        $pages = '';
564
565                        if ($number_of_pages != 0)
566                        {
567                                // Geração das páginas
568                                for ($i = 1; $i <= $number_of_pages ; $i++)
569                                {
570
[3571]571          $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
572                                        $p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
[623]573                                        $p->set_block('mobilemail_t', 'space');
574                                        $p->set_block('mobilemail_t', 'begin_anchor');
575                                        $p->set_block('mobilemail_t', 'end_anchor');
576                                        $p->set_block('mobilemail_t', 'page_item');
577                                        $p->set_block('mobilemail_t', 'begin_strong');
578                                        $p->set_block('mobilemail_t', 'end_strong');
579
580                                        if ($i == $page)
581                                        {
582                                                // Se for a página sendo gerada for a página corrente,
583                                                // não gera a âncora e destaca o número (negrito)
584                                                $p->set_var('end_anchor', '');
585                                                $p->set_var('begin_anchor', '');
586                                                $p->set_var('begin_strong', trim($p->fp('mobilemail_t', 'begin_strong')));
587                                                $p->set_var('end_strong', trim($p->fp('mobilemail_t', 'end_strong')));
588                                        }
589                                        else
590                                        {
591                                                // Senão, gera a âncora
592                                                $p->set_var('begin_strong', '');
593                                                $p->set_var('end_strong', '');
594                                                $p->set_var('end_anchor', trim($p->fp('mobilemail_t', 'end_anchor')));
[3346]595                                                $p->set_var('begin_anchor_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$i");
[623]596                                                $p->set_var('begin_anchor', trim($p->fp('mobilemail_t', 'begin_anchor')));
597                                        }
598
599                                        $p->set_var('page', $i);
600                                        //$pages .= trim($p->fp('mobilemail_t', 'page_item'));
601
602                                }
603                                $pages .= " ".$page." ".lang("of")." ".$number_of_pages." ";
604
605                                // Geração dos links "anterior" e "próximo"
606                                $p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
[3571]607                                $p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
[623]608
609                                //$p->set_block('mobilemail_t', 'space');
610                                $p->set_block('mobilemail_t', 'mail_footer');
611                                $p->set_block('mobilemail_t', 'previous');
612                                $p->set_block('mobilemail_t', 'next');
613
614                                $next_page = $page + 1;
615                                $previous_page = $page - 1;
616
617                                if ($page == 1)
618                                {
619                                        // Se for a primeira página, não imprime o link "anterior""
620                                        $p->set_var('previous', '');
621                                        if ($page == $number_of_pages)
622                                        {
623                                                // Se só existir uma página, não imprime o link "próximo"
624                                                $p->set_var('next', '');
625                                        }
626                                        else
627                                        {
[3346]628                                                $p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page");
[623]629                                                $p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
630                                        }
631
632                                }
633                                else if ($page == $number_of_pages)
634                                {
635                                        // Se for a última página, não imprime o link "próximo"
636                                        $p->set_var('next', '');
[3346]637                                        $p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page");
[623]638                                        $p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
639                                }
640                                else
641                                {
642                                        // Senão, imprime os links "anterior" e "próximo"
[3346]643                                        $p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page");
[623]644                                        $p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
645
[3346]646                                        $p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page");
[623]647                                        $p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
648                                }
649
650                                $p->set_var('pages', $pages);
651                                //$p->pfp('out', 'mail_footer');
652                                $GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_footer'));
653                        }
654
655                }
656
[3571]657                function define_action_message($type) {
658                        switch($type) {
659                                case "clk":
[3600]660                                case "from_mobilecc":
[3602]661                                case "use_draft":
[3571]662                                        $this->template->set_var('action_msg', lang("New message"));
663                                        break;
664                                case "reply_all":
[3600]665                                        $this->template->set_var('action_msg', lang("Reply to All"));
[3571]666                                        break;
667                                case "forward":
668                                        $this->template->set_var('action_msg', lang("Forward"));
669                                        break;                                         
670                        }
[623]671                }
[3571]672               
[623]673                /*
674                 * @function new_msg()
675                 * @abstract Gera o formulário para criar/enviar novo e-mail ou resposta de e-mail.
676                 * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br>
677                 */
[3571]678                function new_msg($params)
[623]679                {
[3571]680                        $this->template->set_file(array('new_msg_t' => 'new_msg.tpl'));
681                        $this->template->set_block('new_msg_t', 'page');
682                        $this->template->set_var('lang_back', lang("back"));
[3829]683                        $this->template->set_var('href_back',$GLOBALS['phpgw_info']['mobiletemplate']->get_back_link());
[3571]684                        $this->template->set_var('lang_calendar', strtoupper(lang("Calendar")));
685                        $this->template->set_var('lang_send', strtoupper(lang("Send")));
[3695]686                        $this->template->set_var('lang_attachment', lang("attachment"));
687                        $this->template->set_var('lang_more_attachment', lang("more attachment"));
[3571]688                        $this->template->set_var('lang_cancel', strtoupper(lang("cancel")));
689                        $this->template->set_var('lang_save_draft', strtoupper(lang("save draft")));
690                        $this->template->set_var('lang_to', lang("To"));
691                        $this->template->set_var('lang_cc', lang("cc"));
692                        $this->template->set_var('lang_subject', lang("Subject"));
693                        $this->template->set_var('lang_mark_as_important', lang("mark as important"));
694                        $this->template->set_var('lang_read_confirmation', lang("read confirmation"));
695                        $this->template->set_var('lang_add_history', lang("add history"));
[3609]696                        $this->template->set_var("show_forward_attachment","none");
[3935]697                        $this->template->set_var("show_check_add_history","none");
[3571]698                       
699                        if(isset($params["error_message"])) {
[3600]700                                $this->template->set_var('input_to', $_POST['input_to']);
701                                $this->template->set_var('input_cc', $_POST['input_cc']);
[3571]702                                $this->template->set_var('subject', $_POST['input_subject']);
703                                $this->template->set_var('msg_number', $_POST['msg_number']);
704                                $this->template->set_var('msg_folder', $_POST['msg_folder']);
705                                $this->template->set_var('body_value', $_POST['body']);
706                                $this->template->set_var('msg_folder', $_POST['folder']);
707                                $this->template->set_var('msg_number', $_POST['reply_msg_number']);
708                                $this->template->set_var('from', $_POST['reply_from']);
709                                $this->template->set_var('check_important', ( ( $_POST['check_important'] ) ? "checked" : "" ) );
710                                $this->template->set_var('check_read_confirmation', ( ( $_POST['check_read_confirmation'] )  ? "checked" : "" ) );
[3935]711                                $this->template->set_var('check_add_history', ( ( $_POST['check_add_history'] )  ? "checked" : "" ) );                         
[1474]712                               
[3571]713                                $GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
714                        } else {
[3602]715                                if (isset($params['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $params['msg_number'], 'msg_folder' => $params['msg_folder'] ) );
[3571]716                               
[3609]717                               
[3600]718                                if($params['type']=="clk")
[3571]719                                {
[3600]720                                        $this->template->set_var('input_to', "");
721                                        $this->template->set_var('input_cc', "");
[3571]722                                        $this->template->set_var('subject', "");
[1474]723                                }
[3600]724                                else if($params['type']=="from_mobilecc")
[3571]725                                {
[3600]726                                        $this->template->set_var('input_to', $_GET['input_to']);
727                                        $this->template->set_var('input_cc', $_GET['input_cc']);
[3571]728                                }
[3600]729                                else if($params['type']=="reply_all"){
730                                        $reply_to_all = $msg['from']['email'];
731                                        if($msg['toaddress2']) $reply_to_all .= ','.$msg['toaddress2'];
732                                        if($msg['cc']) $reply_to_all .= ','.$msg['cc'];
[3935]733                                        if($msg['bcc']) $reply_to_all .= ','.$msg['bcc'];
[3571]734                                       
735                                        $array_emails = explode(',',$reply_to_all);
[3600]736                                        $reply_to_all = '';
[3571]737                                       
[3600]738                                        foreach ($array_emails as $index => $email) {
[3571]739                                                $flag = preg_match('/&lt;(.*?)&gt;/',$email,$reply);
[3600]740                                                $email_to_add = $flag == 0 ? $email.',' : $reply[1].',';
741                                               
742                                                if( strpos($reply_to_all, $email_to_add) === false)
743                                                        $reply_to_all .= $email_to_add;
[3571]744                                        }
[3600]745                                       
746                                        $reply_to_all = substr_replace($reply_to_all, "", strrpos($reply_to_all, ","), strlen($reply_to_all));
747                                       
748                                        $this->template->set_var('input_to', $reply_to_all);
[3571]749                                        $this->template->set_var('subject', "Re:" . $msg['subject']);
750       
751                                        $this->template->set_var('msg_number', $_GET['msg_number']);
752                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);
753                                }
[3600]754                                else if($params['type']=="user_add"){
755                                        $this->template->set_var('input_to', $params['mobile_add_contact']['mobile_mail']);
[3935]756                                        $this->template->set_var('input_cc', $params['mobile_add_contact']['mobile_mail_cc']);
[3600]757                                        $this->template->set_var('subject', $params['mobile_add_contact']['subject_mail']);
758                                        $this->template->set_var('body_value', $params['mobile_add_contact']['body_mail']);
[3571]759       
[3600]760                                        $this->template->set_var('check_important', ( ( $params['mobile_add_contact']['check_important'] ) ? "checked" : "" ) );
761                                        $this->template->set_var('check_read_confirmation', ( ( $params['mobile_add_contact']['check_read_confirmation'] )  ? "checked" : "" ) );
762                                        $this->template->set_var('check_add_history', ( ( $params['mobile_add_contact']['check_add_history'] )  ? "checked" : "" ) );
763                                        $this->template->set_var('msg_number', $params['msg_number']);
764                                        $this->template->set_var('msg_folder', $params['msg_folder']);
765                                       
[3935]766                                        $params["type"] = $params['mobile_add_contact']['type'];
[3571]767                                }
[3600]768                                else if($params['type']=="forward"){
[3571]769                                        $this->template->set_var('from', $msg['toaddress2']);
770       
771                                        $this->template->set_var('subject', "Enc:" . $msg['subject']);
772                                        $this->template->set_var('body_value', strip_tags($msg['body'])); // Usa a função strip_tags() para filtrar
773                                        // as tags que estão presentes no corpo do e-mail.
774                                       
775                                        $this->template->set_var('msg_number', $_GET['msg_number']);
[3609]776                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);   
777                                        if(count($msg['attachments'])>0) {
778                                                $this->template->set_var("lang_forward_attachment",lang("forward attachments"));
779                                                $this->template->set_var("show_forward_attachment","block");
780                                                $this->template->set_block("new_msg_t","forward_attach_block");
781                                                foreach($msg['attachments'] as $forward_attach) {
782                                                        $value = rawurlencode(serialize(array(0=>$msg['msg_folder'],
783                                                                                   1=>$msg['msg_number'],
784                                                                                   3=>$forward_attach['pid'],
785                                                                                   2=>$forward_attach['name'],
786                                                                                   4=>$forward_attach['encoding'])));
787                                                        $this->template->set_var("value_forward_attach",$value);
788                                                        $this->template->set_var("label_forward_attach",$forward_attach['name']);
789                                                        $this->template->fp("forwarding_attachments","forward_attach_block",true);
790                                                }
791                                        }
[3571]792                                }
[3602]793                                else if($params['type']=="use_draft"){
794                                        $this->template->set_var('input_to', $msg['toaddress2']);
795                                        $this->template->set_var('input_cc', $msg['cc']);
796                                        $this->template->set_var('subject', $msg['subject']);
797                                        $this->template->set_var('body_value', strip_tags($msg['body'])); // Usa a função strip_tags() para filtrar
798                                        $this->template->set_var('msg_number', $_GET['msg_number']);
[3609]799                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);
[3602]800                                }
[3935]801                                else if($params['type']=="reply"){
[3571]802                                        $this->template->set_var('from', $msg['toaddress2']);
[3600]803                                        $this->template->set_var('input_to', $msg['from']['email']);
[3571]804       
805                                        $this->template->set_var('subject', "Re:" . $msg['subject']);
806       
807                                        $this->template->set_var('msg_number', $_GET['msg_number']);
808                                        $this->template->set_var('msg_folder', $_GET['msg_folder']);
[3935]809                                } else {
810                                        $this->template->set_var('input_to', "");
811                                        $this->template->set_var('input_cc', "");
812                                        $this->template->set_var('subject', "");
813                                }
[1474]814                        }
815                       
[3935]816                                if($params['type']=="reply" || $params['type']=="forward"  || $params['type']=="reply_all" )
817                                        $this->template->set_var("show_check_add_history","block");
818                       
[3600]819                        //tem que ser realizado no final, pois o tipo user_add é modificado para o tipo que o originou
820                        $this->template->set_var('type', $params['type']);
821                        $this->define_action_message($params['type']);
[3571]822                       
[3600]823                        unset($_SESSION['mobile_add_contact']);
[3571]824                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page'));
[623]825                }
826
[3571]827                                /*
828                 * @function save_draft()
829                 * @abstract Função que salva o email como rascunho
830                 * @author Thiago Antonius
831                 */
832                function save_draft($params)
833                {
834                        $params["folder"] = "INBOX/".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
[3609]835                        $params["FILES"] = $_FILES["FILES"];
836                        $this->common->fixFilesArray($params["FILES"]);
837                        $params['forwarding_attachments'] = $params["forward_attachments"];
[3571]838                        $return = $this->imap_functions->save_msg($params);
839                        if($return["has_error"]) {
840                                $params["error_message"] = lang("draft not save")."<br>".lang("error") . $return["append"];
841                                $this->new_msg( $params );
842                        }else {
[3590]843                                header('Location: index.php?menuaction=menuaction=mobile.ui_home.index&success_message='.lang("draft saved"));
[3571]844                        }                               
845                }
846               
[623]847                /*
848                 * @function send_mail()
849                 * @abstract Função que realiza o envio de e-mails.
850                 * @author Rommel de Brito Cysne <rommel.cysne@serpro.gov.br>
851                 */
852                function send_mail()
853                {
854                        //Chamada da classe phpmailer
[1848]855                        include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.phpmailer.php");
[3609]856                        include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.imap_functions.inc.php");
857                       
[623]858                        //Recebe os dados do form (passados pelo POST)
[3602]859                        $toaddress = $_POST['input_to'];
860                        $ccaddress = $_POST['input_cc'];
[623]861                        $subject = $_POST['input_subject']; //"Mail Subject";
[3609]862                        $body = nl2br($_POST['body']); //"Mail body. Any text.";
[3571]863                        $isImportant = $_POST['check_important'];
864                        $addHistory = $_POST['check_add_history'];
865                        $readConfirmation = $_POST['check_read_confirmation'];
866                        $msgNumber = $_POST['reply_msg_number'];
[3609]867                        $attachments = $_FILES['FILES'];
868                        $this->common->fixFilesArray($attachments);
869                        $forwarding_attachments = $_POST["forward_attachments"];
870                       
[623]871
872                        //Cria objeto
873                        $mail = new PHPMailer();
[3602]874                       
875                        $db_functions = CreateObject('expressoMail1_2.db_functions');
876                       
877                        //chama o getAddrs para carregar os emails caso seja um grupo
878                        $toaddress = implode(',',$db_functions->getAddrs(explode(',',$toaddress)));
879                        $ccaddress = implode(',',$db_functions->getAddrs(explode(',',$ccaddress)));
880                       
881                        if(!$this->imap_functions->add_recipients("to", $toaddress, &$mail))
[623]882                        {
883                                $error_msg = lang("Some addresses in the To field were not recognized. Please make sure that all addresses are properly formed");
884                        }
[3571]885                       
[3602]886                        if(!$this->imap_functions->add_recipients("cc", $ccaddress, &$mail))
[3571]887                        {
888                                $error_msg = lang("Some addresses in the CC field were not recognized. Please make sure that all addresses are properly formed");
[3814]889                        }
[623]890
891                        $mail->IsSMTP();
892                        $mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer'];
893                        $mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort'];
894
[1848]895                        $mail->SaveMessageInFolder = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'];
[623]896                        //Envia os emails em formato HTML; se false -> desativa.
897                        $mail->IsHTML(true);
898                        //Email do remetente da mensagem
899                        $mail->Sender = $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email'];
900                        //Nome do remetente do email
901                        $mail->SenderName = $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
902                        //Assunto da mensagem
903                        $mail->Subject = $subject;
904                        //Corpo da mensagem
905                        $mail->Body .= "<br />$body<br />";
[3571]906                        //Important message
907                        if($isImportant) $mail->isImportant();
908                        //add history
909                        if($addHistory && $msgNumber) {
910                                $msg = $this->imap_functions->get_info_msg(array('msg_number' => $msgNumber ) );
[3814]911                                $mail->Body .= "<br />".$msg['body']."<br />";
[3571]912                        }
913                        //read confirmation
914                        if ($readConfirmation) $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email'];
[623]915
[3609]916                        $imap_functions = new imap_functions();
917                        if (count($attachments)>0) //Attachment
918                        {
919                               
920                                $total_uploaded_size = 0;
921                                $upload_max_filesize = str_replace("M","",$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024;
922                               
923                                foreach ($attachments as $attach)
924                                {
925                                        $mail->AddAttachment($attach['tmp_name'], $attach['name'], "base64", $imap_functions->get_file_type($attach['name']));  // optional name                                       
926                                        $total_uploaded_size = $total_uploaded_size + $attach['size'];
927                                }
928                                if( $total_uploaded_size > $upload_max_filesize){
929
930                                        return $imap_functions->parse_error("message file too big");
931                                }
932                        }
933                        if (count($forwarding_attachments) > 0) { //forward attachment
934                                foreach($forwarding_attachments as $forwarding_attachment)
935                                {
936                                        $file_description = unserialize(rawurldecode($forwarding_attachment));
937                                        $fileContent = $imap_functions->get_forwarding_attachment(
[3814]938                                                $file_description[0],
939                                                $file_description[1],
940                                                $file_description[3],
941                                                $file_description[4]);
[3609]942                                        $fileName = $file_description[2];
943                                        $mail->AddStringAttachment($fileContent,html_entity_decode(rawurldecode($fileName)), $file_description[4], $imap_functions->get_file_type($file_description[2]));
944                                }
945                        }
[3814]946
[3571]947                        if(!$mail->Send()) {
948                                $params["error_message"] = lang("Message not sent")."<br>".lang("error") . $mail->ErrorInfo;
949                                $this->new_msg( $params );
[623]950                        }else {
[3814]951                                if($GLOBALS['phpgw']->session->appsession('mobile.layout','mobile')=="mini_desktop") {
952                                        header('Location: index.php?menuaction=mobile.ui_mobilemail.index&success_message='.lang("Message sent successfully"));
953                                } else {
954                                        header('Location: index.php?menuaction=mobile.ui_home.index&success_message='.lang("Message sent successfully"));
955                                }
[623]956                        }
957                }
958
[1453]959                function confirm_delete_msg()
[3814]960                {
[1453]961                        //Cria um objeto template
962                        //Define o template para mensagens de retorno da funcao
[3571]963                        $this->template->set_file(array('delete_msg_t' => 'delete_msg.tpl'));
964                        $this->template->set_block('delete_msg_t','retorno');                   
[3814]965                        $this->template->set_var('lang_delete_msg', lang("Do you like to delete this message?"));
[3571]966                        $this->template->set_var('lang_yes', lang("Yes"));     
967                        $this->template->set_var('lang_no', lang("No"));
968                        $this->template->set_var('link_yes', 'index.php?menuaction=mobile.ui_mobilemail.delete_msg&msg_number='.$_GET['msg_number'].'&msg_folder='.$_GET['msg_folder']);
969                        $this->template->set_var('link_no', 'index.php?menuaction=mobile.ui_mobilemail.show_msg&amp;msg_number='.$_GET['msg_number'].'&amp;msg_folder='.$_GET['msg_folder']);   
[1453]970                       
[3571]971                        $this->template->pfp('out','retorno'); 
[1453]972                }
[623]973
[3579]974                function delete_msg($params)
[623]975                {
[3589]976
[3656]977                        if ( isset($params['msgs']) || isset($params['msg_number']) )
[1453]978                        {
[3589]979                                $params_messages = array(
[3656]980                                        'msgs_number' => isset($params['msgs'])?implode(",",$params['msgs']):$params['msg_number'],
[3589]981                                        'folder' => $this->folders[$this->current_folder]['folder_name'],
[1453]982                                        'new_folder_name' => 'Trash',
983                                        'new_folder' => 'INBOX/Trash'
984                                );
985                        }       
[623]986
[3656]987                        if (isset($params['msg_number'])){
988                       
989                                $this->imap_functions->move_messages($params_messages);
990
991                                header("Location: index.php?menuaction=mobile.ui_mobilemail.index&success_message=".lang("The messages were moved to trash"));
992                               
993                        }else{
994                                header("Location: index.php?menuaction=mobile.ui_mobilemail.index&error_message=".lang("please select one e-mail"));
995                        }
[1453]996                   
[623]997                }
[1474]998               
999                function get_folder_number($folder_name){
[1848]1000                        foreach($this->folders as $folderNumber => $folder){
[1474]1001                                if($folder['folder_id'] == $folder_name){
[1848]1002                                        return $folderNumber;
[1474]1003                                }
1004                        }
1005                        return 0;
1006                }
1007               
1008                function init_schedule() {
[3600]1009                        $_SESSION['mobile_add_contact'] = array();
1010                        $_SESSION['mobile_add_contact']['mobile_mail']  = $_POST['input_to'];
1011                        $_SESSION['mobile_add_contact']['mobile_mail_cc'] = $_POST['input_cc'];
1012                        $_SESSION['mobile_add_contact']['add_to'] = $_POST['add_to'];
1013                        $_SESSION['mobile_add_contact']['type'] = $_POST['type'];
1014                        $_SESSION['mobile_add_contact']['msg_number'] = $_POST['reply_msg_number'];
1015                        $_SESSION['mobile_add_contact']['msg_folder'] = $_POST['folder'];
1016                        $_SESSION['mobile_add_contact']['subject_mail'] = $_POST['input_subject'];
1017                        $_SESSION['mobile_add_contact']['body_mail'] = $_POST['body'];
1018                        $_SESSION['mobile_add_contact']['check_important'] = $_POST['check_important'];
1019                        $_SESSION['mobile_add_contact']['check_read_confirmation'] = $_POST['check_read_confirmation'];
1020                        $_SESSION['mobile_add_contact']['check_add_history'] = $_POST['check_add_history'];
[3571]1021
[1474]1022                        $ui_cc = CreateObject('mobile.ui_mobilecc');
[3600]1023                        $ui_cc->choose_contact(array("request_from" => "ui_mobilemail.new_msg"));
[1474]1024                }
1025               
1026                function add_recipient() {
[3600]1027                        if($_SESSION['mobile_add_contact']['add_to'] == "to")
1028                                $arr_key_name = "mobile_mail";
1029                        else
1030                                $arr_key_name = "mobile_mail_cc";
[1474]1031                       
[3600]1032                        $arr_mobile_add_contact = $_SESSION['mobile_add_contact'];
[1474]1033                       
[3600]1034                        if(strpos($arr_mobile_add_contact[$arr_key_name], $_GET['mail']) === false)
1035                                $arr_mobile_add_contact[$arr_key_name] .= ( (trim($arr_mobile_add_contact[$arr_key_name]) == "") ? $_GET['mail'] : ",".$_GET['mail']);
[1474]1036                       
[3600]1037                        unset($_SESSION['mobile_add_contact']);
1038                       
1039                        $this->new_msg( array(
1040                                'mobile_add_contact' => $arr_mobile_add_contact,
1041                                'type' => 'user_add',
1042                                'msg_number' => $arr_mobile_add_contact['msg_number'],
1043                                'msg_folder' => $arr_mobile_add_contact['msg_folder']));
[1474]1044                }
1045               
[1714]1046                function list_folders(){                       
1047                        //Define o template para mensagens de retorno da funcao
[3571]1048                        $this->template->set_file(array('folders_t' => 'folders.tpl'));
1049                        $this->template->set_block('folders_t','retorno');
[1714]1050                       
1051                        $folders_list = '';
[1848]1052                        $array_folders = Array();
1053                        $this->folders = $this->imap_functions->get_folders_list(array('noSharedFolders' => true));             
1054                       
1055                        foreach($this->folders as $id => $folder)
[1714]1056                        {
[1848]1057                                if((strpos($folder['folder_id'],'user')===true && !is_array($folder)) || !is_numeric($id))
1058                                        continue;
1059                                        $array_folders[$folder['folder_id']]['id'] = $id;
1060                                        $array_folders[$folder['folder_id']]['folder_name'] = $folder['folder_name'];
1061                        }
1062                       
1063                        foreach($array_folders as $folder_id => $folder)
1064                        {
1065                                if(($folder_id != $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']) && ($folder['id'] != 0)){
1066                                        $folder_name = str_replace('*','',lang($folder['folder_name']));
1067                                        $folder_link = "index.php?menuaction=mobile.ui_mobilemail.mail_list&folder=".$folder['id'];
1068                                        $folders_list .= "<br>:: <a href=".$folder_link.">".$folder_name."</a>";
[1714]1069                                }
1070                        }
[3571]1071                        $this->template->set_var('folders_list', $folders_list);
1072                        $this->template->pfp('out','retorno');                             
[1848]1073
[1714]1074                }
[623]1075
1076        }
1077?>
Note: See TracBrowser for help on using the repository browser.