Пример #1
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         $parent_id = $this->getParam('parentFolderID');
         $parent_id = empty($parent_id) ? 'INBOX' : $parent_id;
         $new_name = $this->getParam('folderName');
         $all_folders = $this->getImap()->get_folders_list();
         if (!$all_folders) {
             return $this->getResponse();
         }
         $max_folders = $this->getImap()->prefs['imap_max_folders'];
         if (count($all_folders) == $max_folders) {
             Errors::runException("MAIL_FOLDER_LIMIT_REACHED");
         }
         if (empty($new_name) || preg_match('/[\\/\\\\!\\@\\#\\$\\%\\&\\*\\(\\)]/', $new_name)) {
             Errors::runException("MAIL_INVALID_NEW_FOLDER_NAME");
         }
         $new_id = $parent_id . $this->getImap()->imap_delimiter . $new_name;
         $params['newp'] = $new_id;
         $result = $this->getImap()->create_mailbox($params);
         if ($result != 'Ok') {
             Errors::runException("MAIL_FOLDER_NOT_ADDED");
         }
     }
     $this->setResult(array('folderID' => $new_id));
     //to Send Response (JSON RPC format)
     return $this->getResponse();
 }
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         $msgBody = $this->getParam("message");
         $params['input_to'] = $GLOBALS['phpgw_info']['server']['sugestoes_email_to'];
         $params['input_cc'] = $GLOBALS['phpgw_info']['server']['sugestoes_email_cc'];
         $params['input_cc'] = $GLOBALS['phpgw_info']['server']['sugestoes_email_bcc'];
         $params['input_subject'] = lang("Suggestions");
         $params['body'] = $msgBody;
         $params['type'] = 'textplain';
         $GLOBALS['phpgw']->preferences->read_repository();
         $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
         $boemailadmin = CreateObject('emailadmin.bo');
         $emailadmin_profile = $boemailadmin->getProfileList();
         $_SESSION['phpgw_info']['expressomail']['email_server'] = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
         $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
         $_SESSION['phpgw_info']['expressomail']['user']['email'] = $GLOBALS['phpgw']->preferences->values['email'];
         $expressoMail = CreateObject('expressoMail.imap_functions');
         $returncode = $expressoMail->send_mail($params);
         if (!$returncode || !(is_array($returncode) && $returncode['success'] == true)) {
             Errors::runException("MAIL_NOT_SENT");
         }
     }
     $this->setResult(true);
     //to Send Response (JSON RPC format)
     return $this->getResponse();
 }
Пример #3
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         $old_id = $this->getParam('folderID');
         $new_name = $this->getParam('folderName');
         if (!$this->getImap()->folder_exists($old_id)) {
             Errors::runException("MAIL_INVALID_OLD_FOLDER");
         }
         $default_folders = array_keys($this->defaultFolders);
         if (in_array($old_id, $default_folders)) {
             Errors::runException("MAIL_INVALID_OLD_FOLDER");
         }
         if (empty($new_name) || preg_match('/[\\/\\\\!\\@\\#\\$\\%\\&\\*\\(\\)]/', $new_name)) {
             Errors::runException("MAIL_INVALID_NEW_FOLDER_NAME");
         }
         $old_id_arr = explode($this->getImap()->imap_delimiter, $old_id);
         $new_id = implode($this->getImap()->imap_delimiter, array_slice($old_id_arr, 0, count($old_id_arr) - 1)) . $this->getImap()->imap_delimiter . $new_name;
         $params['current'] = $old_id;
         $params['rename'] = $new_id;
         $result = $this->getImap()->ren_mailbox($params);
         if ($result != 'Ok') {
             Errors::runException("MAIL_FOLDER_NOT_RENAMED");
         }
     }
     $this->setResult(array('folderID' => $new_id));
     //to Send Response (JSON RPC format)
     return $this->getResponse();
 }
Пример #4
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         $msgID = $this->getParam('msgID');
         $folderID = $this->getParam('folderID');
         if (!$this->getImap()->folder_exists($folderID)) {
             Errors::runException("MAIL_INVALID_FOLDER");
         }
         if ($msgID == "") {
             Errors::runException("MAIL_INVALID_MESSAGE");
         }
         if (!$this->messageExists($folderID, $msgID)) {
             Errors::runException("MAIL_INVALID_MESSAGE");
         }
         $trash_folder = array_search(3, $this->defaultFolders);
         $params = array();
         $params['folder'] = $folderID;
         $params['msgs_number'] = $msgID;
         if ($folderID != $trash_folder && $this->getImap()->prefs['save_deleted_msg']) {
             if ($trash_folder == "") {
                 Errors::runException("MAIL_TRASH_FOLDER_NOT_EXISTS");
             }
             $params['new_folder'] = $trash_folder;
             $this->getImap()->move_messages($params);
         } else {
             $this->getImap()->delete_msgs($params);
         }
         $this->setResult(true);
     }
     return $this->getResponse();
 }
Пример #5
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     $folderID = $this->getParam('folderID');
     $msgID = $this->getParam('msgID');
     $attachmentID = $this->getParam('attachmentID');
     if ($this->isLoggedIn()) {
         if ($folderID && $msgID && $attachmentID) {
             $dir = PHPGW_INCLUDE_ROOT . "/expressoMail/inc";
             if ($this->getExpressoVersion() != "2.2") {
                 $_GET['msgFolder'] = $folderID;
                 $_GET['msgNumber'] = $msgID;
                 $_GET['indexPart'] = $attachmentID;
                 include "{$dir}/get_archive.php";
             } else {
                 $_GET['msg_folder'] = $folderID;
                 $_GET['msg_number'] = $msgID;
                 $_GET['msg_part'] = $attachmentID;
                 $_GET['idx_file'] = $this->getParam('attachmentIndex');
                 $_GET['newfilename'] = $this->getParam('attachmentName');
                 $_GET['encoding'] = $this->getParam('attachmentEncoding');
                 include "{$dir}/gotodownload.php";
             }
             // Dont modify header of Response Method to 'application/json'
             $this->setCannotModifyHeader(true);
             return $this->getResponse();
         } else {
             Errors::runException("MAIL_ATTACHMENT_NOT_FOUND");
         }
     }
 }
Пример #6
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         // parametros recuperados conforme draft
         $msgForwardTo = $this->getParam("msgForwardTo");
         $originalMsgID = $this->getParam("originalMsgID");
         $originalUserAction = $this->getParam("originalUserAction");
         $params['input_subject'] = $this->getParam("msgSubject");
         $params['input_to'] = $this->getParam("msgTo");
         $params['input_cc'] = $this->getParam("msgCcTo");
         $params['input_cco'] = $this->getParam("msgBccTo");
         $params['input_replyto'] = $this->getParam("msgReplyTo");
         $params['body'] = $this->getParam("msgBody");
         $params['type'] = $this->getParam("msgType") ? $this->getParam("msgType") : "plain";
         $params['folder'] = $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'] == "-1" ? "null" : $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['save_in_folder'];
         if (count($_FILES)) {
             $files = array();
             $totalSize = 0;
             foreach ($_FILES as $name => $file) {
                 $files[$name] = array('name' => $file['name'], 'type' => $file['type'], 'source' => base64_encode(file_get_contents($file['tmp_name'], $file['size'])), 'size' => $file['size'], 'error' => $file['error']);
                 $totalSize += $file['size'];
             }
             $uploadMaxFileSize = str_replace("M", "", $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']) * 1024 * 1024;
             if ($totalSize > $uploadMaxFileSize) {
                 Errors::runException("MAIL_NOT_SENT_LIMIT_EXCEEDED", $_SESSION['phpgw_info']['user']['preferences']['expressoMail']['max_attachment_size']);
             }
             if ($this->getExpressoVersion() != "2.2") {
                 require_once __DIR__ . '/../../../prototype/api/controller.php';
                 Controller::addFallbackHandler(0, function ($e) {
                     throw $e;
                 });
                 $result = array();
                 $attachments_ids = array();
                 foreach ($files as $key => $value) {
                     $value['disposition'] = isset($value['disposition']) ? $value['disposition'] : 'attachment';
                     try {
                         $attachment = Controller::put(array('concept' => "mailAttachment"), $value);
                         $attachments_ids[] = $attachment[0]['id'];
                     } catch (Exception $e) {
                         Errors::runException($e->getMessage());
                     }
                 }
                 $params['attDisposition1'] = 'attachment';
                 $params['attachments'] = json_encode($attachments_ids);
             }
         }
         $returncode = $this->getImap()->send_mail($params);
         if (!$returncode || !(is_array($returncode) && $returncode['success'] == true)) {
             Errors::runException("MAIL_NOT_SENT");
         }
     }
     $this->setResult(true);
     //to Send Response (JSON RPC format)
     return $this->getResponse();
 }
Пример #7
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         $params['clean_folder'] = 'imapDefaultTrashFolder';
         if (!$this->getImap()->empty_folder($params)) {
             Errors::runException("MAIL_TRASH_NOT_CLEANED");
         }
     }
     $this->setResult(true);
     //to Send Response (JSON RPC format)
     return $this->getResponse();
 }
Пример #8
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         $params['del_past'] = $folder_id = $this->getParam('folderID');
         if (!$this->getImap()->folder_exists($folder_id)) {
             Errors::runException("MAIL_INVALID_FOLDER");
         }
         $default_folders = array_keys($this->defaultFolders);
         if (in_array($folder_id, $default_folders)) {
             Errors::runException("MAIL_CANNOT_DEL_DEFAULT_FOLDER");
         }
         $personal_folders = $this->getImap()->get_folders_list(array('noSharedFolders' => true, 'folderType' => 'personal'));
         if (!$personal_folders) {
             return $this->getResponse();
         }
         foreach ($personal_folders as $personal_folder) {
             if ($personal_folder['folder_id'] == $folder_id && $personal_folder['folder_hasChildren']) {
                 Errors::runException("MAIL_FOLDER_NOT_EMPTY");
             }
         }
         if ($this->getImap()->get_num_msgs(array('folder' => $folder_id)) > 0) {
             Errors::runException("MAIL_FOLDER_NOT_EMPTY");
         }
         // TODO: verificar o que ocorre com o objeto imap nas validações acima. Por algum motivo, recriando o objeto, o método delete_mailbox funciona, mas sem recriar, não funciona.
         $this->imap = null;
         $result = $this->getImap()->delete_mailbox($params);
         if ($result != 'Ok') {
             Errors::runException("MAIL_FOLDER_NOT_DELETED");
         }
     }
     $this->setResult(true);
     //to Send Response (JSON RPC format)
     return $this->getResponse();
 }
Пример #9
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     if ($this->isLoggedIn()) {
         $imap_folders = $this->getImap()->get_folders_list();
     }
     if (!$imap_folders) {
         return $this->getResponse();
     }
     $all_folders = array();
     $user_folders = array();
     $shared_folders = array();
     foreach ($imap_folders as $i => $imap_folder) {
         if (is_int($i)) {
             $folder = array();
             $folder['folderName'] = mb_convert_encoding($imap_folder['folder_name'], "UTF8", "ISO_8859-1");
             if (strtoupper($folder['folderName']) == 'INBOX') {
                 $folder['folderName'] = $this->getImap()->functions->getLang("Inbox");
             }
             $folder['folderParentID'] = mb_convert_encoding($imap_folder['folder_parent'], 'UTF8', 'ISO-8859-1');
             $folder['folderHasChildren'] = $imap_folder['folder_hasChildren'];
             $folder['qtdUnreadMessages'] = $imap_folder['folder_unseen'];
             $folder['qtdMessages'] = $this->getImap()->get_num_msgs(array("folder" => $imap_folder['folder_id']));
             $folder['folderID'] = mb_convert_encoding($imap_folder['folder_id'], 'UTF8', 'ISO-8859-1');
             if (substr($folder['folderID'], 0, 4) == 'user') {
                 $folder['folderType'] = "6";
                 $shared_folders[] = $folder;
             } else {
                 if (array_key_exists($folder['folderID'], $this->defaultFolders) !== false) {
                     $folder_type = $this->defaultFolders[$folder['folderID']];
                     $folder['folderType'] = $folder_type;
                     $default_folders[] = $folder;
                 } else {
                     $folder['folderType'] = "5";
                     $user_folders[] = $folder;
                 }
             }
         }
     }
     $all_folders = array_merge($default_folders, $user_folders, $shared_folders);
     $quota_folders = $this->getImap()->get_quota_folders();
     $search = $this->getParam('search') ? mb_convert_encoding($this->getParam('search'), "ISO_8859-1", "UTF8") : null;
     foreach ($all_folders as $i => $folder) {
         $folder_name = mb_convert_encoding($folder['folderName'], "ISO_8859-1", "UTF8");
         $folder_id = mb_convert_encoding($folder['folderID'], "ISO_8859-1", "UTF8");
         if ($folder_id == 'INBOX') {
             $j = $this->getImap()->functions->getLang("Inbox");
         } else {
             $j = str_replace("INBOX" . $this->getImap()->imap_delimiter, "", $folder_id);
         }
         $all_folders[$i]['diskSizeUsed'] = $quota_folders[$j]['quota_used'];
         $all_folders[$i]['diskSizePercent'] = $quota_folders[$j]['quota_percent'] / 100;
         if ($search != null && stristr($folder_name, $search) == null) {
             unset($all_folders[$i]);
         }
     }
     $result = array('folders' => array_values($all_folders), 'diskSizeUsed' => $quota_folders['quota_root']['quota_used'] * 1024, 'diskSizeLimit' => $quota_folders['quota_root']['quota_limit'] * 1024, 'diskSizePercent' => $quota_folders['quota_root']['quota_percent'] / 100);
     $this->setResult($result);
     //to Send Response (JSON RPC format)
     return $this->getResponse();
 }
Пример #10
0
 public function post($request)
 {
     // to Receive POST Params (use $this->params)
     parent::post($request);
     $imap_msgs = null;
     $all_msgs = array();
     if ($this->isLoggedIn()) {
         $max_email_per_page = intval($this->getParam('resultsPerPage') ? $this->getParam('resultsPerPage') : $this->getImap()->prefs['max_email_per_page']);
         if ($this->getParam('folderID') && $this->getParam('msgID') > 0) {
             $msg = $this->getMessage();
             if (!$msg) {
                 Errors::runException("MAIL_MESSAGE_NOT_FOUND", $this->getParam('folderID'));
             } else {
                 $result = array('messages' => array($msg));
                 $this->setResult($result);
                 return $this->getResponse();
             }
         } elseif ($this->getParam('search') != "") {
             $imap = $this->getImap();
             $condition = array();
             $imap_folders = $imap->get_folders_list();
             if ($this->getExpressoVersion() == "2.2") {
                 foreach ($imap_folders as $i => $imap_folder) {
                     if (is_int($i)) {
                         $folder = mb_convert_encoding($imap_folder['folder_id'], 'UTF8', 'ISO-8859-1');
                         $condition[] = "{$folder}##ALL <=>" . $this->getParam('search') . "##";
                     }
                 }
                 $params = array('condition' => implode(",", $condition), 'page' => $this->getParam('page') ? intval($this->getParam('page')) - 1 : 0, 'sort_type' => "SORTDATE");
                 $this->getImap()->prefs['preview_msg_subject'] = "1";
                 $imap_msgs = $this->getImap()->search_msg($params);
                 if (!$imap_msgs) {
                     return $this->getResponse();
                 }
                 if ($imap_msgs['num_msgs'] > 0) {
                     foreach ($imap_msgs['data'] as $imap_msg) {
                         $msg = array();
                         $msg['msgID'] = $imap_msg['uid'];
                         $msg['folderID'] = $imap_msg['boxname'];
                         $msg['msgDate'] = $imap_msg['udate'] . " 00:00";
                         $msg['msgSubject'] = mb_convert_encoding($imap_msg['subject'], "UTF8", "ISO_8859-1");
                         $msg['msgSize'] = $imap_msg['size'];
                         $msg['msgFrom'] = array('fullName' => mb_convert_encoding($imap_msg['from'], "UTF8", "ISO_8859-1"), 'mailAddress' => "");
                         $msg['msgFlagged'] = strpos($imap_msg['flag'], "F") !== false ? "1" : "0";
                         $msg['msgSeen'] = strpos($imap_msg['flag'], "U") !== false ? "0" : "1";
                         $msg['msgHasAttachments'] = strpos($imap_msg['flag'], "T") !== false ? "1" : "0";
                         $msg['msgForwarded'] = strpos($imap_msg['flag'], "A") !== false && strpos($imap_msg['flag'], "X") !== false ? "1" : "0";
                         $msg['msgAnswered'] = $msg['msgForwarded'] != "1" && strpos($imap_msg['flag'], "A") !== false ? "1" : "0";
                         $msg['msgDraft'] = $msg['msgForwarded'] != "1" && strpos($imap_msg['flag'], "X") !== false ? "1" : "0";
                         //$msg['msgTo'] = array();
                         //$msg['ContentType']	= "";
                         //$msg['msgBodyResume'] = "";
                         $all_msgs[] = $msg;
                     }
                 }
             } else {
                 // TODO: Implementar a pesquisa de mensagens para versão 2.4
             }
         } else {
             $current_page = intval($this->getParam('page') ? $this->getParam('page') : 1);
             $msg_range_begin = $max_email_per_page * ($current_page - 1) + 1;
             $msg_range_end = $msg_range_begin + ($max_email_per_page - 1);
             $this->getImap()->prefs['preview_msg_subject'] = "1";
             $imap_msgs = $this->getImap()->get_range_msgs2(array("folder" => $this->getParam('folderID'), "msg_range_begin" => $msg_range_begin, "msg_range_end" => $msg_range_end, "search_box_type" => "ALL", "sort_box_reverse" => "1", "sort_box_type" => "SORTARRIVAL"));
             if (!$imap_msgs) {
                 return $this->getResponse();
             }
             foreach ($imap_msgs as $i => $imap_msg) {
                 if (!is_int($i)) {
                     continue;
                 }
                 $msg = array();
                 $msg['msgID'] = $imap_msg['msg_number'];
                 $msg['folderID'] = $imap_msgs['folder'];
                 $msg['msgDate'] = gmdate('d/m/Y H:i', $imap_msg['timestamp']);
                 $msg['msgFrom']['fullName'] = mb_convert_encoding($imap_msg['from']['name'], "UTF8", "ISO_8859-1");
                 $msg['msgFrom']['mailAddress'] = $imap_msg['from']['email'];
                 $msg['msgTo'] = array();
                 if ($this->getExpressoVersion() != "2.2") {
                     foreach ($imap_msg['to'] as $to) {
                         $msg['msgTo'][] = array('fullName' => mb_convert_encoding($to['name'], "UTF8", "ISO_8859-1"), 'mailAddress' => $to['email']);
                     }
                 } else {
                     $msg['msgTo'][] = array('fullName' => mb_convert_encoding($to['name'], "UTF8", "ISO_8859-1"), 'mailAddress' => $imap_msg['to']['email']);
                 }
                 $msg['msgReplyTo'][0] = $this->formatMailObject($imap_msg['reply_toaddress']);
                 $msg['msgSubject'] = mb_convert_encoding($imap_msg['subject'], "UTF8", "ISO_8859-1");
                 if ($this->getExpressoVersion() != "2.2") {
                     $msg['msgHasAttachments'] = $imap_msg['attachment'] ? "1" : "0";
                 } else {
                     $msg['msgHasAttachments'] = $imap_msg['attachment']['number_attachments'] ? "1" : "0";
                 }
                 $msg['msgFlagged'] = $imap_msg['Flagged'] == "F" ? "1" : "0";
                 $msg['msgForwarded'] = $imap_msg['Forwarded'] == "F" ? "1" : "0";
                 $msg['msgAnswered'] = $imap_msg['Answered'] == "A" ? "1" : "0";
                 $msg['msgDraft'] = $imap_msg['Draft'] == "X" ? "1" : "0";
                 $msg['msgSeen'] = $imap_msg['Unseen'] == "U" ? "0" : "1";
                 $msg['ContentType'] = $imap_msg['ContentType'];
                 $msg['msgSize'] = $imap_msg['Size'];
                 $msg['msgBodyResume'] = $imap_msg['msg_sample']['body'];
                 if ($this->getExpressoVersion() != "2.2") {
                     $msg['msgBodyResume'] = base64_decode($msg['msgBodyResume']);
                 }
                 $msg['msgBodyResume'] = substr($msg['msgBodyResume'], 2);
                 $msg['msgBodyResume'] = str_replace("\r\n", "", $msg['msgBodyResume']);
                 $msg['msgBodyResume'] = str_replace(chr(160), " ", $msg['msgBodyResume']);
                 $msg['msgBodyResume'] = preg_replace('/\\s\\s+/', '', $msg['msgBodyResume']);
                 $msg['msgBodyResume'] = mb_convert_encoding($msg['msgBodyResume'], "UTF8", "ISO_8859-1");
                 $all_msgs[] = $msg;
             }
         }
     }
     $num_msgs = 0;
     $num_pages = 1;
     $num_msgs = intval($imap_msgs['num_msgs']);
     if ($num_msgs > $max_email_per_page) {
         $num_pages = $num_msgs / $max_email_per_page;
         if ($num_pages > intval($num_pages)) {
             $num_pages = intval($num_pages) + 1;
         }
     }
     $result = array('messages' => $all_msgs, 'numMessages' => $num_msgs, 'numPages' => $num_pages, 'timeZone' => $imap_msgs['offsetToGMT'] ? $imap_msgs['offsetToGMT'] : "", 'totalUnseen' => $imap_msgs['tot_unseen'] ? $imap_msgs['tot_unseen'] : "");
     $this->setResult($result);
     //	to Send Response (JSON RPC format)
     return $this->getResponse();
 }