*
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
//TODO: Criar a Classe Widget.
include_once(PHPGW_INCLUDE_ROOT.'/expressoMail1_2/inc/class.imap_functions.inc.php');
// Classe principal do Mini Mail
class ui_mobilemail{
// Define as funções públicas
var $public_functions = array(
'mail_list' => True,
'change_folder' => True,
'change_page' => True,
'show_msg' => True,
'send_mail' => True,
//'reply_msg' => True,
'new_msg' => True,
'delete_msg' => True,
'confirm_delete_msg' => True,
'init_schedule' => true,
'add_recipients' => true,
'add_recipient' => true,
'list_folders' => true,
'save_draft' => true,
'mark_message_with_flag' => true
);
var $template;
var $common;
var $folders; // Pastas imap
var $current_folder; // Pasta corrente
var $current_page; // Página corrente da lista de e-mails da pasta corrente
var $imap_functions; // Variável que recebe um objeto do tipo class.imap_functions.inc.php
var $allowed_tags = '
'; // Tags html que não serão removidas
// ao mostrar corpo do e-mail
/*
* @function mobilemail
* @abstract Método construtor da classe principal do Mini Mail
* @author Mário César Kolling
*/
function ui_mobilemail()
{
$this-> load_session();
$this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
$this->common = CreateObject('mobile.common_functions');
// Recupera atributos da classe gravados na sessão
$folders = $GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile');
$current_folder = $GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile');
$current_page = $GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile');
// Inicializa a classe class.imap_functions.inc.php
$this->imap_functions = new imap_functions();
// Testa a existência dos atributos da classe recuperadas da sessão, e as carrega ou inicializa.
if ($folders)
{
$this->folders = $folders;
}
else
{
$this->folders = $this->imap_functions->get_folders_list(array('noSharedFolders' => true));
}
if ($current_folder)
{
$this->current_folder = $current_folder;
$current_page = 1;
}
else
{
$this->current_folder = 0; // Define o folder INBOX como o folder corrente
}
if ($current_page)
{
$this->current_page = $current_page;
}
else
{
$this->current_page = 1; // Define a primeira página como página padrão
}
}
/*
* @function save_session
* @abstract Salva os atributos da classe na sessão
* @author Mário César Kolling
*/
function save_session()
{
$GLOBALS['phpgw']->session->appsession('mobilemail.folders','mobile',$this->folders);
$GLOBALS['phpgw']->session->appsession('mobilemail.current_folder','mobile',$this->current_folder);
$GLOBALS['phpgw']->session->appsession('mobilemail.current_page','mobile',$this->current_page);
}
/*
* @function change_page
* @abstract Troca a página de exibição da lista de e-mails, e mostra a nova página
* @author Mário César Kolling
*/
function change_page()
{
if (isset($_GET['page']))
{
$this->current_page = $_GET['page'];
}
$this->mail_list();
$this->save_session();
}
/*
* @function change_folder
* @abstract Troca a pasta do imap, e mostra a primeira página da nova pasta
* @author Mário César Kolling
*/
function change_folder($params)
{
$folder = $params['folder'];
if (isset($folder))
{
$this->current_folder = $folder;
$this->current_page = 1;
}
$GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
$this->mail_list($params);
$this->save_session();
}
function mark_message_with_flag($params=array())
{
$return = $this->imap_functions->set_messages_flag($params);
if($return)
header('Location: index.php?menuaction=menuaction=mobile.ui_mobilemail.change_folder&folder='.$this->current_folder);
else
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"]);
exit;
}
/*
* @function show_msg
* @abstract Mostra a mensagem de e-mail requisitada
* @author Mário César Kolling
*/
// TODO: retirar msg_folder dos parâmentros necessários no GET e usar $this->current_folder
function show_msg($params = array())
{
$msg = $this->imap_functions->get_info_msg($params);
// Carrega o template
$this->template->set_file(array('view_msg' => 'view_msg.tpl'));
$this->template->set_block('view_msg', 'page');
$this->template->set_block('view_msg', 'begin_anchor');
$this->template->set_block('view_msg', 'end_anchor');
$this->template->set_var('lang_back', lang("back"));
$this->template->set_var('lang_reading_message', lang("Reading Message"));
// Define o cabeçalho do e-mail
$this->template->set_var('lang_from', lang("From"));
$this->template->set_var('from', $msg['from']['full']);
$this->template->set_var('lang_cc', lang("cc"));
$this->template->set_var('cc', $msg['cc']);
$this->template->set_var('size', $this->common->borkb($msg['Size']));
$this->template->set_var('lang_subject', lang("Subject"));
$this->template->set_var('subject', $msg['subject']);
$this->template->set_var('date', $msg['msg_day']." ".$msg['msg_hour']);
// Mostra o corpo do e-mail
$this->template->set_var('body', strip_tags($msg['body'], $this->allowed_tags)); // Usa a função strip_tags() para filtrar
// as tags que estão presentes no corpo do e-mail.
$this->template->set_var('lang_link', lang("Return"));
$this->template->set_var('return_link', "index.php?menuaction=mobile.ui_mobilemail.mail_list");
$this->template->set_var('lang_reply_all', lang("Reply to all"));
$this->template->set_var('lang_forward', lang("Forward"));
$this->template->set_var('lang_mark_as_unread', lang("mark as unread"));
$this->template->set_var('lang_reply', lang("Reply"));
$this->template->set_var('lang_delete', lang("Delete"));
$msg_number = $params['msg_number'];
$msg_folder = $params['msg_folder'];
$this->template->set_var('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");
$this->template->set_var('reply_link', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder");
$this->template->set_var('delete_link', "index.php?menuaction=mobile.ui_mobilemail.confirm_delete_msg&msg_number=$msg_number&msg_folder=$msg_folder");
$this->template->set_var('reply_all_link', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=reply_all");
$this->template->set_var('forward_link', "index.php?menuaction=mobile.ui_mobilemail.new_msg&msg_number=$msg_number&msg_folder=$msg_folder&type=forward");
if (!empty($msg['attachments']))
{
$attachs = "
".lang("This message has the follow attachments:")."
";
foreach($msg['attachments'] as $key => $attach) {
if(is_array($attach)) {
//$attachs.=$attach['name']." ";
$attachs.="".
lang('Download').": ".$attach['name']."
";
}
}
$this->template->set_var('attachment_message', $attachs);
}
else
{
$this->template->set_var('attachment_message', lang('This message don\'t have attachment(s)'));
}
$this->template->parse('view_msg_t', 'end_anchor');
$this->template->parse('view_msg_t', 'begin_anchor');
$GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
$GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page'));
}
/*
* @function index
* @abstract Página inicial da aplicação mobilemail, mantém o estado atual. Ou seja, mostra lista de e-mails
* do folder e página definidos pelos parâmetros current_folder e current_page.
* @author Mário César Kolling
*/
// TODO: Talvez seja melhor voltar sempre para o Inbox e primeira página
function index()
{
$this->print_folder_selection();
$this->mail_list();
$this->save_session();
}
function load_session(){
/************************************\
* Inicialização do expressoMail1_2 *
\************************************/
// Get Data from ldap_manager and emailadmin.
$ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
$boemailadmin = CreateObject('emailadmin.bo');
$emailadmin_profile = $boemailadmin->getProfileList();
$_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
$_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
$_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
$_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
$_SESSION['phpgw_info']['expressomail']['user']['email'] = $GLOBALS['phpgw']->preferences->values['email'];
// Fix problem with cyrus delimiter changes in preferences.
// Dots in names: enabled/disabled.
$save_in_folder = @eregi_replace("INBOX/", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']);
$save_in_folder = @eregi_replace("INBOX.", "INBOX".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDelimiter'], $save_in_folder);
$_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'] = $save_in_folder;
// End Fix.
// Loading Admin Config Module
$c = CreateObject('phpgwapi.config','expressoMail1_2');
$c->read_repository();
$current_config = $c->config_data;
$_SESSION['phpgw_info']['server']['expressomail']['expressoMail_enable_log_messages'] = $current_config['expressoMail_enable_log_messages'];
// Begin Set Anti-Spam options.
$_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_ham'] = $current_config['expressoMail_command_for_ham'];
$_SESSION['phpgw_info']['server']['expressomail']['expressoMail_command_for_spam'] = $current_config['expressoMail_command_for_spam'];
$_SESSION['phpgw_info']['server']['expressomail']['expressoMail_use_spam_filter'] = $current_config['expressoMail_use_spam_filter'];
// echo '';
// End Set Anti-Spam options.
// Set Imap Folder names options
$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultTrashFolder'] : "Trash";
$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'] : "Drafts";
$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'] : "Spam";
$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] = $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] ? $_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'] : "Sent";
// include("../expressoMail1_2/inc/load_lang.php");
}
/*
* @function print_folder_selection
* @abstract Imprime o folder corrente (INBOX)
* @author Mário César Kolling
*/
function print_folder_selection()
{
$this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
$this->template->set_block('mobilemail_t', 'inbox_folder_list');
$this->template->set_var('lang_folder', lang('Folder'));
$folder = str_replace("*","",lang($this->folders[$this->current_folder]['folder_name']));
if(!$this->current_folder == 0){
$this->template->set_var('lang_inbox', $folder.' :: '.lang('Inbox').'');
}else{
$this->template->set_var('lang_inbox', lang('Inbox'));
}
//$this->template->set_var('folder_items', $folder_items);
$this->template->parse('mobilemail_t', 'inbox_folder_list');
//$this->template->fpf('out', 'mobilemail_t');
$GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'mobilemail_t'));
}
/*
* @function old_print_folder_selection
* @abstract Imprime na tela a caixa de seleção de folders
* @author Mário César Kolling
*/
function old_print_folder_selection()
{
// Processa as options
$folder_items = '';
foreach ($this->folders as $i => $j)
{
$option_selected = '';
$this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
$this->template->set_block('mobilemail_t', 'folder_item');
if (is_numeric($i))
{
if ($i == $this->current_folder)
{
$option_selected = 'selected="selected"';
}
$this->template->set_var('option_selected', $option_selected);
$this->template->set_var('folder_id', $j['folder_id']);
$this->template->set_var('folder_name', $j['folder_id']); // Mudar... provavelmente usar preg_replace
// para substituir cpf pelo nome do usuário.
if ($j['folder_unseen'] > 0)
{
$this->template->set_var('folder_unseen', ' - ('.$j['folder_unseen'].')');
}
$folder_items .= $this->template->fp('mobile_t', 'folder_item');
}
}
// Processa o select
$this->template->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
$this->template->set_block('mobilemail_t', 'folder_list');
$this->template->set_var('folder_items', $folder_items);
$this->template->parse('mobilemail_t', 'folder_list');
//$this->template->pfp('out', 'mobilemail_t');
$GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'mobilemail_t'));
}
/*
* @function mail_list
* @abstract Imprime a lista de e-mails
* @author Mário César Kolling
*/
function mail_list($params)
{
if($params['folder']){
$this->current_folder = $params['folder'];
}else{
$this->current_folder = 0;
}
$this->print_folder_selection();
$this->messages_per_page =
isset($GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page'])?
$GLOBALS['phpgw_info']['user']['preferences']['mobile']['max_message_per_page']:10;
if (!isset($this->number_of_messages))
{
$params_num_msg = array(
'folder' => $this->folders[$this->current_folder]['folder_id'],
);
$this->number_of_messages = $this->imap_functions->get_num_msgs($params_num_msg);
}
// Recalcular as páginas
$this->pages = ceil($this->number_of_messages/$this->messages_per_page);
$page = $this->current_page;
if($_POST["searchEmail"]){
$params_mobile_search = array(
'filter' => $_POST["searchEmail"]
);
$messages = $this->imap_functions->mobile_search($params_mobile_search);
}else{
$params_get_range_msgs = array(
'folder' => $this->folders[$this->current_folder]['folder_id'],
'msg_range_begin' => $this->current_page * $this->messages_per_page - ($this->messages_per_page - 1),
'msg_range_end' => $this->current_page * $this->messages_per_page,
'sort_box_type' => 'SORTARRIVAL',
'sort_box_reverse' => 1
);
$messages = $this->imap_functions->get_range_msgs2($params_get_range_msgs);
}
$this->print_mails_list($messages);
$this->print_page_navigation($this->pages, $this->current_page);
}
/*
* @function print_mails_list
* @abstract Imprime a lista de mensagens
* @author Mário César Kolling
* @param array Um array com a lista de mensagens recuperado por $this->imap_functions->get_range_msgs2($params)
*/
function print_mails_list($messages)
{
$functions = CreateObject('mobile.common_functions');
$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
$p->set_file(
Array(
'mobilemail_t' => 'mails_list.tpl'
)
);
$p->set_block('mobilemail_t', 'rows_mails');
$p->set_block('mobilemail_t', 'row_mails');
$p->set_block('mobilemail_t', 'no_messages');
if(count($messages)>1) { //O array de emails tem pelo menos uma posição com o total de mensagens.
$bg = "par";
foreach($messages as $id => $message) {
if(($id==='num_msgs') ||($id==='total_msgs'))
continue;
if($message['from']['name'])
$from_name = $functions->strach_string($message['from']['name'],20);
else
$from_name = $functions->strach_string($message['from']['email'],20);
$p->set_var('bg',$bg=="par"?$bg="reset-dt":$bg="par");
$p->set_var('from',$from_name);
$p->set_var('mail_time',$message['smalldate']);
$p->set_var('mail_from',$functions->strach_string($message['from']['email'],23));
$p->set_var('subject',$functions->strach_string($message['subject'],25));
$p->set_var('size',$functions->borkb($message['Size']));
$p->set_var('lang_attachment',lang('ATTACHMENT'));
$p->set_var('msg_number', $message['msg_number']);
$p->set_var('msg_folder', isset($message['msg_folder'])?
$message['msg_folder']:$this->folders[$this->current_folder]['folder_id']);
if($message['attachment']['number_attachments']>0) {
$p->set_var('show_attach','inline');
$p->set_var('no_attach_space','none');
}
else {
$p->set_var('show_attach','none');
$p->set_var('no_attach_space','block');
}
$p->fp('rows','row_mails',True);
}
}
else {
$p->set_var("lang_no_results",lang("no results found"));
$p->parse("rows","no_messages");
}
return $p->fp('out','rows_mails');
}
/*
* @funtion print_page_navigation
* @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.
* @author Mário César Kolling
* @param integer Número de páginas que serão geradas
* @param integer Página corrente
*/
// TODO: mover este método para a classe page_navigation subclasse de widget
function print_page_navigation($number_of_pages, $page = 1)
{
$pages = '';
if ($number_of_pages != 0)
{
// Geração das páginas
for ($i = 1; $i <= $number_of_pages ; $i++)
{
$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
$p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
$p->set_block('mobilemail_t', 'space');
$p->set_block('mobilemail_t', 'begin_anchor');
$p->set_block('mobilemail_t', 'end_anchor');
$p->set_block('mobilemail_t', 'page_item');
$p->set_block('mobilemail_t', 'begin_strong');
$p->set_block('mobilemail_t', 'end_strong');
if ($i == $page)
{
// Se for a página sendo gerada for a página corrente,
// não gera a âncora e destaca o número (negrito)
$p->set_var('end_anchor', '');
$p->set_var('begin_anchor', '');
$p->set_var('begin_strong', trim($p->fp('mobilemail_t', 'begin_strong')));
$p->set_var('end_strong', trim($p->fp('mobilemail_t', 'end_strong')));
}
else
{
// Senão, gera a âncora
$p->set_var('begin_strong', '');
$p->set_var('end_strong', '');
$p->set_var('end_anchor', trim($p->fp('mobilemail_t', 'end_anchor')));
$p->set_var('begin_anchor_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$i");
$p->set_var('begin_anchor', trim($p->fp('mobilemail_t', 'begin_anchor')));
}
$p->set_var('page', $i);
//$pages .= trim($p->fp('mobilemail_t', 'page_item'));
}
$pages .= " ".$page." ".lang("of")." ".$number_of_pages." ";
// Geração dos links "anterior" e "próximo"
$p = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
$p->set_file(array('mobilemail_t' => 'mobilemail.tpl'));
//$p->set_block('mobilemail_t', 'space');
$p->set_block('mobilemail_t', 'mail_footer');
$p->set_block('mobilemail_t', 'previous');
$p->set_block('mobilemail_t', 'next');
$next_page = $page + 1;
$previous_page = $page - 1;
if ($page == 1)
{
// Se for a primeira página, não imprime o link "anterior""
$p->set_var('previous', '');
if ($page == $number_of_pages)
{
// Se só existir uma página, não imprime o link "próximo"
$p->set_var('next', '');
}
else
{
$p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page");
$p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
}
}
else if ($page == $number_of_pages)
{
// Se for a última página, não imprime o link "próximo"
$p->set_var('next', '');
$p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page");
$p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
}
else
{
// Senão, imprime os links "anterior" e "próximo"
$p->set_var('previous_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$previous_page");
$p->set_var('previous', trim($p->fp('mobilemail_t', 'previous')));
$p->set_var('next_href', "index.php?menuaction=mobile.ui_mobilemail.change_page&folder=$this->current_folder&page=$next_page");
$p->set_var('next', trim($p->fp('mobilemail_t', 'next')));
}
$p->set_var('pages', $pages);
//$p->pfp('out', 'mail_footer');
$GLOBALS['phpgw_info']['mobiletemplate']->set_content($p->fp('out', 'mail_footer'));
}
}
function define_action_message($type) {
switch($type) {
case "clk":
case "cc_mob":
$this->template->set_var('action_msg', lang("New message"));
break;
case "reply_all":
$this->template->set_var('action_msg', lang("Reply All"));
break;
case "user_add":
$this->template->set_var('action_msg', lang("Add Recipient"));
break;
case "forward":
$this->template->set_var('action_msg', lang("Forward"));
break;
}
}
/*
* @function new_msg()
* @abstract Gera o formulário para criar/enviar novo e-mail ou resposta de e-mail.
* @author Rommel de Brito Cysne
*/
function new_msg($params)
{
$this->template->set_file(array('new_msg_t' => 'new_msg.tpl'));
$this->template->set_block('new_msg_t', 'page');
$this->template->set_block('new_msg_t', 'add_recipient_block');
$this->template->set_var('lang_back', lang("back"));
$this->template->set_var('lang_calendar', strtoupper(lang("Calendar")));
$this->template->set_var('lang_send', strtoupper(lang("Send")));
$this->template->set_var('lang_attachment', strtoupper(lang("attachment")));
$this->template->set_var('lang_cancel', strtoupper(lang("cancel")));
$this->template->set_var('lang_save_draft', strtoupper(lang("save draft")));
$this->template->set_var('type', $_GET['type']);
$this->template->set_var('lang_to', lang("To"));
$this->template->set_var('lang_cc', lang("cc"));
$this->template->set_var('lang_subject', lang("Subject"));
$this->template->set_var('lang_mark_as_important', lang("mark as important"));
$this->template->set_var('lang_read_confirmation', lang("read confirmation"));
$this->template->set_var('lang_add_history', lang("add history"));
$this->template->set_var('type', $_REQUEST['type']);
$this->template->parse('add_recipient_box', 'add_recipient_block', true);
$this->define_action_message($_REQUEST['type']);
if(isset($params["error_message"])) {
$this->template->set_var('to', $_POST['input_to']);
$this->template->set_var('to_mail', $_POST['input_to_mail']);
$this->template->set_var('cc', $_POST['input_cc']);
$this->template->set_var('cc_mail', $_POST['input_cc_mail']);
$this->template->set_var('subject', $_POST['input_subject']);
$this->template->set_var('msg_number', $_POST['msg_number']);
$this->template->set_var('msg_folder', $_POST['msg_folder']);
$this->template->set_var('body_value', $_POST['body']);
$this->template->set_var('msg_folder', $_POST['folder']);
$this->template->set_var('msg_number', $_POST['reply_msg_number']);
$this->template->set_var('from', $_POST['reply_from']);
$this->template->set_var('check_important', ( ( $_POST['check_important'] ) ? "checked" : "" ) );
$this->template->set_var('check_read_confirmation', ( ( $_POST['check_read_confirmation'] ) ? "checked" : "" ) );
$this->template->set_var('check_add_history', ( ( $_POST['check_add_history'] ) ? "checked" : "" ) );
$GLOBALS['phpgw_info']['mobiletemplate']->set_error_msg($params["error_message"]);
} else {
if (isset($_GET['msg_number'])) $msg = $this->imap_functions->get_info_msg(array('msg_number' => $_GET['msg_number'] ) );
if($_REQUEST['type']=="clk")
{
$this->template->set_var('to', "");
$this->template->set_var('to_mail', "");
$this->template->set_var('cc', "");
$this->template->set_var('cc_mail', "");
$this->template->set_var('subject', "");
}
else if($_REQUEST['type']=="cc_mob")
{
$this->template->set_var('to', $_GET['input_to']);
$this->template->set_var('to_mail', $_GET['input_to_mail']);
$this->template->set_var('cc', $_GET['input_cc']);
$this->template->set_var('cc_mail', $_GET['input_cc_mail']);
$this->template->set_var('subject', "");
$this->template->set_var('msg_number', $_GET['msg_number']);
$this->template->set_var('msg_folder', $_GET['msg_folder']);
$this->template->set_var('read_only', 'readonly');
}
else if($_REQUEST['type']=="reply_all"){
$reply_to_all = $msg['from']['full'];
$reply_to_all = $msg['toaddress2'] ? $reply_to_all.','.$msg['toaddress2']:$reply_to_all;
$reply_to_all = $msg['cc'] ? $reply_to_all.','.$msg['cc']:$reply_to_all;
$reply_to_all = $msg['bcc'] ? $reply_to_all.','.$msg['bcc']:$reply_to_all;
$names = implode(',
',explode(',',$reply_to_all));
$array_emails = explode(',',$reply_to_all);
$reply_to_all ='';
foreach ($array_emails as $index => $email){
$flag = preg_match('/<(.*?)>/',$email,$reply);
$reply_to_all .= $flag == 0 ? $email.', ':$reply[1].', ';
}
$this->template->set_var('to', $reply_to_all);
$this->template->set_var('to_mail', $_GET['input_to_mail']);
$this->template->set_var('subject', "Re:" . $msg['subject']);
$this->template->set_var('msg_number', $_GET['msg_number']);
$this->template->set_var('msg_folder', $_GET['msg_folder']);
}
else if($_REQUEST['type']=="user_add"){
$listMail = implode(',',$_SESSION['mobile_mail']);
$this->template->set_var('to', $listMail);
$this->template->set_var('to_mail', $listMail);
$this->template->set_var('subject', $_SESSION['subject_mail']);
$this->template->set_var('body_value', $_SESSION['body_mail']);
$this->template->set_var('msg_number', $_GET['msg_number']);
$this->template->set_var('msg_folder', $_GET['msg_folder']);
}
else if($_REQUEST['type']=="forward"){
$this->template->set_var('from', $msg['toaddress2']);
$mail_to = $msg['from']['full'];
$this->template->set_var('subject', "Enc:" . $msg['subject']);
$this->template->set_var('body_value', strip_tags($msg['body'])); // Usa a função strip_tags() para filtrar
// as tags que estão presentes no corpo do e-mail.
$this->template->set_var('msg_number', $_GET['msg_number']);
$this->template->set_var('msg_folder', $_GET['msg_folder']);
}
else{
$this->template->set_var('from', $msg['toaddress2']);
$mail_to = $msg['from']['full'];
$this->template->set_var('to', $msg['from']['name']);
$this->template->set_var('to_mail', $msg['from']['email']);
$this->template->set_var('subject', "Re:" . $msg['subject']);
$this->template->set_var('msg_number', $_GET['msg_number']);
$this->template->set_var('msg_folder', $_GET['msg_folder']);
$this->template->set_var('read_only', "readonly");
}
}
$_SESSION['mobile_mail'] = array();
$GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out', 'page'));
}
/*
* @function save_draft()
* @abstract Função que salva o email como rascunho
* @author Thiago Antonius
*/
function save_draft($params)
{
$params["folder"] = "INBOX/".$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultDraftsFolder'];
$return = $this->imap_functions->save_msg($params);
if($return["has_error"]) {
$params["error_message"] = lang("draft not save")."
".lang("error") . $return["append"];
$this->new_msg( $params );
}else {
$ui_home = CreateObject('mobile.ui_home');
$params["success_message"] = lang("draft saved");
$ui_home->index( $params );
}
}
/*
* @function send_mail()
* @abstract Função que realiza o envio de e-mails.
* @author Rommel de Brito Cysne
*/
function send_mail()
{
//Chamada da classe phpmailer
include_once(PHPGW_SERVER_ROOT."/expressoMail1_2/inc/class.phpmailer.php");
//Recebe os dados do form (passados pelo POST)
$userName = $_POST['input_to']; //"User Someone";
$userMail = $_POST['input_to_mail']; //"user.someone@mail.com.br";
$ccUserName = $_POST['input_cc'];
$ccUserMail = $_POST['input_cc_mail'];
$subject = $_POST['input_subject']; //"Mail Subject";
$body = $_POST['body']; //"Mail body. Any text.";
$isImportant = $_POST['check_important'];
$addHistory = $_POST['check_add_history'];
$readConfirmation = $_POST['check_read_confirmation'];
$msgNumber = $_POST['reply_msg_number'];
if($userMail == "") $userMail = $userName;
if($ccUserMail == "") $ccUserMail = $ccUserName;
//Cria objeto
$mail = new PHPMailer();
if(!$this->imap_functions->add_recipients("to", $userMail, &$mail))
{
$error_msg = lang("Some addresses in the To field were not recognized. Please make sure that all addresses are properly formed");
}
if(!$this->imap_functions->add_recipients("cc", $ccUserMail, &$mail))
{
$error_msg = lang("Some addresses in the CC field were not recognized. Please make sure that all addresses are properly formed");
}
$mail->IsSMTP();
$mail->Host = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpServer'];
$mail->Port = $_SESSION['phpgw_info']['expressomail']['email_server']['smtpPort'];
$mail->SaveMessageInFolder = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'];
//Envia os emails em formato HTML; se false -> desativa.
$mail->IsHTML(true);
//Email do remetente da mensagem
$mail->Sender = $mail->From = $_SESSION['phpgw_info']['expressomail']['user']['email'];
//Nome do remetente do email
$mail->SenderName = $mail->FromName = $_SESSION['phpgw_info']['expressomail']['user']['fullname'];
//Assunto da mensagem
$mail->Subject = $subject;
//Corpo da mensagem
$mail->Body .= "
$body
";
//Important message
if($isImportant) $mail->isImportant();
//add history
if($addHistory && $msgNumber) {
$msg = $this->imap_functions->get_info_msg(array('msg_number' => $msgNumber ) );
$mail->Body .= "
".$msg['body']."
";
}
//read confirmation
if ($readConfirmation) $mail->ConfirmReadingTo = $_SESSION['phpgw_info']['expressomail']['user']['email'];
//Se o e-mail nao for enviado por qualquer motivo...
if(!$mail->Send()) {
$params["error_message"] = lang("Message not sent")."
".lang("error") . $mail->ErrorInfo;
$this->new_msg( $params );
}else {
$ui_home = CreateObject('mobile.ui_home');
$params["success_message"] = lang("Message sent successfully");
$ui_home->index($params);
}
}
function confirm_delete_msg()
{
//Cria um objeto template
//Define o template para mensagens de retorno da funcao
$this->template->set_file(array('delete_msg_t' => 'delete_msg.tpl'));
$this->template->set_block('delete_msg_t','retorno');
$this->template->set_var('lang_delete_msg', lang("Do you like to delete this message?"));
$this->template->set_var('lang_yes', lang("Yes"));
$this->template->set_var('lang_no', lang("No"));
$this->template->set_var('link_yes', 'index.php?menuaction=mobile.ui_mobilemail.delete_msg&msg_number='.$_GET['msg_number'].'&msg_folder='.$_GET['msg_folder']);
$this->template->set_var('link_no', 'index.php?menuaction=mobile.ui_mobilemail.show_msg&msg_number='.$_GET['msg_number'].'&msg_folder='.$_GET['msg_folder']);
$this->template->pfp('out','retorno');
}
function delete_msg()
{
if (isset($_GET['msg_number']))
{
$params = array(
'msgs_number' => $_GET['msg_number'],
'folder' => $_GET['msg_folder'],
'new_folder_name' => 'Trash',
'new_folder' => 'INBOX/Trash'
);
}
$this->imap_functions->move_messages($params);
//Cria um objeto template
//Define o template para mensagens de retorno da funcao
$this->template->set_file(array('move_msg_t' => 'sent_msg.tpl'));
$this->template->set_block('move_msg_t','retorno');
//@header('Refresh: 1; url=./ui_mobilemail.index?folder='.$this->current_folder);
$this->template->set_var('msg', lang("The message was moved to trash"));
$this->template->pfp('out','retorno');
}
function get_folder_number($folder_name){
foreach($this->folders as $folderNumber => $folder){
if($folder['folder_id'] == $folder_name){
return $folderNumber;
}
}
return 0;
}
function retorna()
{
}
function init_schedule() {
if($_POST['input_to'] != '' && !is_null($_POST['input_to']))
array_push($_SESSION['mobile_mail'],$_POST['input_to']);
$_SESSION['subject_mail'] = $_POST['input_subject'];
$_SESSION['body_mail'] = $_POST['body'];
$this->add_recipients();
}
function add_recipients() {
$ui_cc = CreateObject('mobile.ui_mobilecc');
$ui_cc->contacts_list('mobilemail');
}
function add_recipient() {
$participants = $_SESSION["mobile_mail"];
if(!is_array($participants))
$participants = array();
$participants[$_GET['cn']] = $_GET['mail'];
$_SESSION["mobile_mail"] = $participants;
$this->add_recipients();
}
function list_folders(){
//Define o template para mensagens de retorno da funcao
$this->template->set_file(array('folders_t' => 'folders.tpl'));
$this->template->set_block('folders_t','retorno');
$folders_list = '';
$array_folders = Array();
$this->folders = $this->imap_functions->get_folders_list(array('noSharedFolders' => true));
foreach($this->folders as $id => $folder)
{
if((strpos($folder['folder_id'],'user')===true && !is_array($folder)) || !is_numeric($id))
continue;
$array_folders[$folder['folder_id']]['id'] = $id;
$array_folders[$folder['folder_id']]['folder_name'] = $folder['folder_name'];
}
foreach($array_folders as $folder_id => $folder)
{
if(($folder_id != $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder']) && ($folder['id'] != 0)){
$folder_name = str_replace('*','',lang($folder['folder_name']));
$folder_link = "index.php?menuaction=mobile.ui_mobilemail.mail_list&folder=".$folder['id'];
$folders_list .= "
:: ".$folder_name."";
}
}
$this->template->set_var('folders_list', $folders_list);
$this->template->pfp('out','retorno');
}
}
?>