2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
41 ********************************************************************************/
42 // hack to allow "&", "%" and "+" through a $_GET var
43 // set by ie_test_open_popup() javascript call
44 foreach($_REQUEST as $k => $v) {
45 $v = str_replace('::amp::', '&', $v);
46 $v = str_replace('::plus::', '+', $v);
47 $v = str_replace('::percent::', '%', $v);
51 require_once('modules/InboundEmail/language/en_us.lang.php');
60 global $app_list_strings;
64 $jsCustomVersion = $sugar_config['js_custom_version'];
65 $sugar_version = $sugar_version;
72 $novalidate_cert = '';
74 $deletedFoldersList = "";
76 ///////////////////////////////////////////////////////////////////////////////
79 $popupBoolean = false;
80 if (isset($_REQUEST['target']) && $_REQUEST['target'] == 'Popup') {
83 if (isset($_REQUEST['target1']) && $_REQUEST['target1'] == 'Popup') {
88 $title = $mod_strings['LBL_SELECT_SUBSCRIBED_FOLDERS'];
89 $msg = $mod_strings['LBL_TEST_WAIT_MESSAGE'];
92 $subdcriptionFolderHelp = $app_strings['LBL_EMAIL_SUBSCRIPTION_FOLDER_HELP'];
94 if(isset($_REQUEST['ssl']) && ($_REQUEST['ssl'] == "true" || $_REQUEST['ssl'] == 1)) {
98 $searchField = !empty($_REQUEST['searchField']) ? $_REQUEST['searchField'] : "";
99 $multipleString = "multiple=\"true\"";
100 if (!empty($searchField)) {
101 $subdcriptionFolderHelp = "";
102 $multipleString = "";
103 if ($searchField == 'trash') {
104 $title = $mod_strings['LBL_SELECT_TRASH_FOLDERS'];
106 $title = $mod_strings['LBL_SELECT_SENT_FOLDERS'];
112 $ie = new InboundEmail();
113 if(!empty($_REQUEST['ie_id'])) {
114 $ie->retrieve($_REQUEST['ie_id']);
116 $ie->email_user = $_REQUEST['email_user'];
117 $ie->server_url = $_REQUEST['server_url'];
118 $ie->port = $_REQUEST['port'];
119 $ie->protocol = $_REQUEST['protocol'];
120 //Bug 23083.Special characters in email password results in IMAP authentication failure
121 if(!empty($_REQUEST['email_password'])) {
122 $ie->email_password = html_entity_decode($_REQUEST['email_password'], ENT_QUOTES);
123 $ie->email_password = str_rot13($ie->email_password);
125 //$ie->mailbox = $_REQUEST['mailbox'];
127 $ie->mailbox = 'INBOX';
130 $returnArray = $ie->getFoldersListForMailBox();
131 $foldersList = $returnArray['foldersList'];
132 if ($returnArray['status']) {
133 $msg = $returnArray['statusMessage'];
134 $requestMailBox = explode(",", $_REQUEST['mailbox']);
135 $foldersListArray = explode(",", $foldersList);
136 $deletedFoldersString = "";
138 if (!empty($requestMailBox) && !empty($foldersListArray)) {
139 foreach($requestMailBox as $mailbox) {
140 if (!in_array($mailbox, $foldersListArray)) {
142 $deletedFoldersString = $deletedFoldersString . " ,";
144 $deletedFoldersString = $deletedFoldersString . $mailbox;
149 if (!empty($deletedFoldersString)) {
150 $deletedFoldersList = $mod_strings['LBL_DELETED_FOLDERS_LIST'];
151 $deletedFoldersList = sprintf($deletedFoldersList, $deletedFoldersString);
154 $msg = $returnArray['statusMessage'];
159 ///////////////////////////////////////////////////////////////////////////////
161 ///////////////////////////////////////////////////////////////////////////////
163 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">
173 if (!empty($subdcriptionFolderHelp)) {
183 <td>'.$subdcriptionFolderHelp.'
191 <div id="sf_deletedFoldersList" style="display:none;">
192 '.$deletedFoldersList.'
200 <select '.$multipleString.' size="12" name="inboundmailboxes" id="sf_inboundmailboxes">
214 <input type="button" style="" class="button" value="'.$app_strings['LBL_DONE_BUTTON_LABEL'].'" onclick="setMailbox();">
215 <input type="button" class="button" value="'.$app_strings['LBL_EMAIL_CANCEL'].'" onclick="SUGAR.inboundEmail.listDlg.hide()">
227 ///////////////////////////////////////////////////////////////////////////////
229 ///////////////////////////////////////////////////////////////////////////////
230 //// COMPLETE RENDERING OF THE POPUP
231 echo '<input type="hidden" id="sf_returnstatus" name="returnstatus" value="'. $returnArray['status'] .'">';
232 echo '<input type="hidden" id="sf_foldersList" name="foldersList" value="'. $foldersList .'">';
233 echo '<input type="hidden" id="sf_selectedfoldersList" name="selectedfoldersList" value="'. implode(",", $requestMailBox) .'">';
234 echo '<input type="hidden" id="sf_searchField" name="searchField" value="'. $searchField .'">';
237 <script type="text/javascript">
238 SUGAR.inboundEmail.listDlg.setHeader("'.$title.'");
239 function setMailbox(box) {
240 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
241 var selectedmbox = "";
243 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
244 if (inboundmailboxes.options[i].selected) {
246 selectedmbox = selectedmbox + ",";
248 selectedmbox = selectedmbox + inboundmailboxes.options[i].value;
252 var searchFieldValue = document.getElementById("sf_searchField").value;
253 if (searchFieldValue.length > 0) {
254 if (searchFieldValue == "trash") {
255 var tf = document.getElementById("trashFolder");
256 tf.value = selectedmbox;
257 } else if(searchFieldValue == "sent") {
258 var sf = document.getElementById("sentFolder");
259 sf.value = selectedmbox;
262 var mb = document.getElementById("mailbox");
263 mb.value = selectedmbox;
265 SUGAR.inboundEmail.listDlg.hide();
267 function switchMsg() {
268 if(typeof(document.getElementById("sf_msg")) != "undefined") {
269 document.getElementById("sf_msg").innerHTML = "'.$msg.'";
270 var deletedFoldersList = document.getElementById("sf_deletedFoldersList");
271 deletedFoldersList.innerHTML = "'. $deletedFoldersList .'";
272 if (deletedFoldersList.innerHTML.length > 0) {
273 deletedFoldersList.style.display = "";
275 var selectedFoldersListObject = new Object();
276 var selectedFoldersListArray = document.getElementById("sf_selectedfoldersList").value.split(",");
277 for (var j = 0 ; j < selectedFoldersListArray.length ; j++) {
278 selectedFoldersListObject[selectedFoldersListArray[j]] = selectedFoldersListArray[j];
280 if (document.getElementById("sf_returnstatus").value == "1") {
281 var foldersList = document.getElementById("sf_foldersList").value;
282 var foldersArray = foldersList.split(",");
283 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
284 for (var i = 0 ; i < foldersArray.length ; i++) {
285 var opt = new Option(foldersArray[i], foldersArray[i]);
286 if (selectedFoldersListObject[foldersArray[i]] != null) {
289 inboundmailboxes.options.add(opt);
292 var selectdFoldersValue = document.getElementById("sf_selectedfoldersList").value;
293 var searchFieldValue = document.getElementById("sf_searchField").value;
294 if (selectdFoldersValue.length <= 0) {
295 if (searchFieldValue.length > 0) {
296 if (searchFieldValue == "trash") {
297 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
298 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
299 if ((inboundmailboxes.options[i].text.search(/trash/i) != -1) ||
300 (inboundmailboxes.options[i].text.search(/delete/i) != -1)) {
302 inboundmailboxes.options[i].selected = true;
307 if (searchFieldValue == "sent") {
308 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
309 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
310 if (inboundmailboxes.options[i].text.search(/sent/i) != -1) {
312 inboundmailboxes.options[i].selected = true;