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