".$mod_strings['LBL_ENABLE_IMAP_SUPPORT'].""; exit(); } require_once('Smarty_setup.php'); require_once("data/Tracker.php"); require_once('include/logging.php'); require_once('include/utils/utils.php'); require_once('include/utils/UserInfoUtil.php'); require_once("modules/Webmails/MailBox.php"); require_once("modules/Webmails/Webmails.php"); require_once("modules/Webmails/MailParse.php"); if(trim($_REQUEST["search_input"]) != ''){ $searchstring = vtlib_purify($_REQUEST["search_type"]).' "'.vtlib_purify($_REQUEST["search_input"]).'"'; $MailBox = new MailBox($mailbox,$start-1,$searchstring); } else $MailBox = new MailBox($mailbox,$start-1); // Check for a valid mailbox and also make sure the needed php_imap module is installed $mods = parsePHPModules(); if(!$MailBox->mbox || !isset($mods["imap"]) || $mods["imap"] == "") { echo "

".$mod_strings['LBL_CONFIGURE_MAIL_SETTINGS']."

"; exit(); } // Set the system into degraded service mode where needed $degraded_service='false'; if($MailBox->mail_protocol == "imap" || $MailBox->mail_protocol == "pop3") $degraded_service='true'; if($_POST["command"] == "check_mbox_all") { exit(); $boxes = array(); $i=0; foreach ($_SESSION["mailboxes"] as $key => $val) { $MailBox = new MailBox($key); $box = imap_status($MailBox->mbox, "{".$MailBox->imapServerAddress."}".$key, SA_ALL); $boxes[$i]["name"] = $key; if($val == $box->unseen) $boxes[$i]["newmsgs"] = 0; elseif($val < $box->unseen) { $boxes[$i]["newmsgs"] = ($box->unseen-$val); $_SESSION["mailboxes"][$key] = $box->unseen; } else { $boxes[$i]["newmsgs"] = 0; $_SESSION["mailboxes"][$key] = $box->unseen; } $i++; imap_close($MailBox->mbox); } $ret = ''; if(count($boxes) > 0) { $ret = '{"msgs":['; for($i=0,$num=count($boxes);$i<$num;$i++) { $ret .= '{"msg":'; $ret .= '{'; $ret .= '"box":"'.$boxes[$i]["name"].'",'; $ret .= '"newmsgs":"'.$boxes[$i]["newmsgs"].'"}'; if(($i+1) == $num) $ret .= '}'; else $ret .= '},'; } $ret .= ']}'; } echo $ret; flush(); exit(); } //This is invoked from Webmails.js as a result of the periodic event function call, checks only for NEW mails; this in turn checks for new mails in all the mailboxes if($_POST["command"] == "check_mbox") { $adb->println("Inside check_mbox AJAX command"); $search = imap_search($MailBox->mbox, 'NEW'); //if($search === false) {echo "failed";flush();exit();} $adb->println("imap_search($MailBox->mbox, $criteria) ===> "); $adb->println($search); $data = imap_fetch_overview($MailBox->mbox,implode(',',$search)); $num=sizeof($data); $adb->println("fetched data using imap_fetch_overview ==>"); $adb->println($data); $ret = ''; if($num > 0) { $ret = '{"mails":['; for($i=0;$i<$num;$i++) { //Added condition to avoid show the deleted mails and readed mails if($data[$i]->deleted == 0)// && $data[$i]->seen == 0) { $ret .= '{"mail":'; $ret .= '{'; $ret .= '"mailid":"'.$data[$i]->msgno.'",'; $ret .= '"subject":"'.substr($data[$i]->subject,0,40).'",'; $ret .= '"date":"'.substr($data[$i]->date,0,30).'",'; $ret .= '"from":"'.substr($data[$i]->from,0,20).'",'; $ret .= '"to":"'.$data[$i]->to.'",'; echo ' to field is ' .$data[$i]->to; $email = new Webmails($MailBox->mbox,$data[$i]->msgno); if($email->has_attachments) $ret .= '"attachments":"1"}'; else $ret .= '"attachments":"0"}'; if(($i+1) == $num) $ret .= '}'; else $ret .= '},'; } } $ret .= ']}'; $adb->println("Ret Value ==> $ret"); } echo $ret; flush(); imap_close($MailBox->mbox); exit(); } ?> mbox,$mailid,$_REQUEST["mvbox"]); } imap_expunge($MailBox->mbox); imap_close($MailBox->mbox); $MailBox = new MailBox($mailbox); $elist = $MailBox->mailList; $num_mails = $elist['count']; $start_page = ceil($num_mails/$MailBox->mails_per_page); imap_close($MailBox->mbox); echo "start=".$start_page.";"; echo "id=".$mailid.";"; flush(); exit(); } // Function to remove directories used for tmp attachment storage function SureRemoveDir($dir) { if(!$dh = @opendir($dir)) return; while (($obj = readdir($dh))) { if($obj=='.' || $obj=='..') continue; if (!@unlink($dir.'/'.$obj)) { SureRemoveDir($dir.'/'.$obj); } else { $file_deleted++; } } if (@rmdir($dir)) $dir_deleted++; } $save_path=$root_directory.'modules/Webmails/tmp'; $user_dir=$save_path."/".$_SESSION["authenticated_user_id"]; // Get the list of mails for this mailbox $elist = $MailBox->mailList; $numEmails = $elist["count"]; $mails_per_page = $MailBox->mails_per_page; // Calculate paging information ahead before retrieving overviews if($start == 1 || $start == "") { $start_message=$numEmails; } else { $start_message=($numEmails-(($start-1)*$mails_per_page)); } $numPages = ceil($numEmails/$MailBox->mails_per_page); if($numPages > 1) { if($start != 1){ $navigationOutput = "  "; $navigationOutput .= "  "; } if($start <= ($numPages-1)){ $navigationOutput .= "  "; $navigationOutput .= "  "; } } if(isPermitted('Contacts','EditView','') == 'yes') $show_qualify = "yes"; else $show_qualify = "no"; $overview=$elist["overview"]; ?> "; $search_fields = Array("SUBJECT","BODY","TO","CC","BCC","FROM"); $listview_header = array("".$mod_strings['LBL_INFO']."","".$mod_strings['LBL_LIST_SUBJECT']."","".$mod_strings['LABEL_DATE']."","".$mod_strings['LABEL_FROM']."","".$mod_strings['LBL_DEL'].""); $listview_entries = array(); $displayed_msgs=0; $info = imap_status($MailBox->mbox, "{".$MailBox->imapServerAddress."}", SA_UNSEEN); $unread_msgs = $info->unseen; //$new_msgs=0; if(($numEmails) <= 0) $listview_entries[0][] = ''.$mod_strings['LBL_NO_EMAILS'].''; else { if(isset($_REQUEST["search"]) && trim($_REQUEST["search_input"]) != '') { for($l=$MailBox->mails_per_page-1;$l>=0;$l--){ if($overview[$l]->msgno!="") $listview_entries[] = show_msg($mails,$overview[$l]->msgno); } }else{ $i=1; while ($i<=$MailBox->mails_per_page) { if($start_message > 0){ $listview_entries[] = show_msg($mails,$start_message); $start_message--; } $i++; } } flush(); // MAIN LOOP // Main loop to create listview entries } $search_html = ''; // Build folder list and move_to dropdown box $list = imap_getmailboxes($MailBox->mbox, "{".$MailBox->imapServerAddress."}", "*"); sort($list); $i=0; if (is_array($list)) { $boxes = ''; } imap_close($MailBox->mbox); $smarty = new vtigerCRM_Smarty; $smarty->assign("SEARCH_VALUE",vtlib_purify($_REQUEST['search_input'])); $smarty->assign("USERID", $current_user->id); $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); $smarty->assign("IMAGE_PATH",$image_path); $smarty->assign("LISTENTITY", $listview_entries); $smarty->assign("LISTHEADER", $listview_header); $smarty->assign("SEARCH_HTML", $search_html); $smarty->assign("MODULE","Webmails"); $smarty->assign("SINGLE_MOD",getTranslatedString('SINGLE_'.$currentModule, $currentModule)); $smarty->assign("BUTTONS",$other_text); $smarty->assign("CATEGORY","My Home Page"); $smarty->assign("NAVIGATION", $navigationOutput); $smarty->assign("FOLDER_SELECT", $boxes); $smarty->assign("NUM_EMAILS", $numEmails); $smarty->assign("MAILBOX", $MailBox->mailbox); $smarty->assign("ACCOUNT", $MailBox->display_name); $smarty->assign("BOXLIST",$folders); $smarty->assign("DEGRADED_SERVICE",$degraded_service); $smarty->assign("THEME",$theme); $smarty->display("Webmails.tpl"); ?>