2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 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;
70 $novalidate_cert = '';
72 $deletedFoldersList = "";
74 ///////////////////////////////////////////////////////////////////////////////
77 $popupBoolean = false;
78 if (isset($_REQUEST['target']) && $_REQUEST['target'] == 'Popup') {
81 if (isset($_REQUEST['target1']) && $_REQUEST['target1'] == 'Popup') {
86 $title = $mod_strings['LBL_SELECT_SUBSCRIBED_FOLDERS'];
87 $msg = $mod_strings['LBL_TEST_WAIT_MESSAGE'];
90 $subdcriptionFolderHelp = $app_strings['LBL_EMAIL_SUBSCRIPTION_FOLDER_HELP'];
92 if(isset($_REQUEST['ssl']) && ($_REQUEST['ssl'] == "true" || $_REQUEST['ssl'] == 1)) {
96 $searchField = !empty($_REQUEST['searchField']) ? $_REQUEST['searchField'] : "";
97 $multipleString = "multiple=\"true\"";
98 if (!empty($searchField)) {
99 $subdcriptionFolderHelp = "";
100 $multipleString = "";
101 if ($searchField == 'trash') {
102 $title = $mod_strings['LBL_SELECT_TRASH_FOLDERS'];
104 $title = $mod_strings['LBL_SELECT_SENT_FOLDERS'];
110 $ie = new InboundEmail();
111 if(!empty($_REQUEST['ie_id'])) {
112 $ie->retrieve($_REQUEST['ie_id']);
114 $ie->email_user = $_REQUEST['email_user'];
115 $ie->server_url = $_REQUEST['server_url'];
116 $ie->port = $_REQUEST['port'];
117 $ie->protocol = $_REQUEST['protocol'];
118 //Bug 23083.Special characters in email password results in IMAP authentication failure
119 if(!empty($_REQUEST['email_password'])) {
120 $ie->email_password = html_entity_decode($_REQUEST['email_password'], ENT_QUOTES);
121 $ie->email_password = str_rot13($ie->email_password);
123 //$ie->mailbox = $_REQUEST['mailbox'];
125 $ie->mailbox = 'INBOX';
128 $returnArray = $ie->getFoldersListForMailBox();
129 $foldersList = $returnArray['foldersList'];
130 if ($returnArray['status']) {
131 $msg = $returnArray['statusMessage'];
132 $requestMailBox = explode(",", $_REQUEST['mailbox']);
133 $foldersListArray = explode(",", $foldersList);
134 $deletedFoldersString = "";
136 if (!empty($requestMailBox) && !empty($foldersListArray)) {
137 foreach($requestMailBox as $mailbox) {
138 if (!in_array($mailbox, $foldersListArray)) {
140 $deletedFoldersString = $deletedFoldersString . " ,";
142 $deletedFoldersString = $deletedFoldersString . $mailbox;
147 if (!empty($deletedFoldersString)) {
148 $deletedFoldersList = $mod_strings['LBL_DELETED_FOLDERS_LIST'];
149 $deletedFoldersList = sprintf($deletedFoldersList, $deletedFoldersString);
152 $msg = $returnArray['statusMessage'];
157 ///////////////////////////////////////////////////////////////////////////////
159 ///////////////////////////////////////////////////////////////////////////////
161 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">
171 if (!empty($subdcriptionFolderHelp)) {
181 <td>'.$subdcriptionFolderHelp.'
189 <div id="sf_deletedFoldersList" style="display:none;">
190 '.$deletedFoldersList.'
198 <select '.$multipleString.' size="12" name="inboundmailboxes" id="sf_inboundmailboxes">
212 <input type="button" style="" class="button" value="'.$app_strings['LBL_DONE_BUTTON_LABEL'].'" onclick="setMailbox();">
213 <input type="button" class="button" value="'.$app_strings['LBL_EMAIL_CANCEL'].'" onclick="SUGAR.inboundEmail.listDlg.hide()">
225 ///////////////////////////////////////////////////////////////////////////////
227 ///////////////////////////////////////////////////////////////////////////////
228 //// COMPLETE RENDERING OF THE POPUP
229 echo '<input type="hidden" id="sf_returnstatus" name="returnstatus" value="'. $returnArray['status'] .'">';
230 echo '<input type="hidden" id="sf_foldersList" name="foldersList" value="'. htmlspecialchars($foldersList) .'">';
231 echo '<input type="hidden" id="sf_selectedfoldersList" name="selectedfoldersList" value="'. implode(",", $requestMailBox) .'">';
232 echo '<input type="hidden" id="sf_searchField" name="searchField" value="'. $searchField .'">';
235 <script type="text/javascript">
236 SUGAR.inboundEmail.listDlg.setHeader("'.$title.'");
237 function setMailbox(box) {
238 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
239 var selectedmbox = "";
241 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
242 if (inboundmailboxes.options[i].selected) {
244 selectedmbox = selectedmbox + ",";
246 selectedmbox = selectedmbox + inboundmailboxes.options[i].value;
250 var searchFieldValue = document.getElementById("sf_searchField").value;
251 if (searchFieldValue.length > 0) {
252 if (searchFieldValue == "trash") {
253 var tf = document.getElementById("trashFolder");
254 tf.value = selectedmbox;
255 } else if(searchFieldValue == "sent") {
256 var sf = document.getElementById("sentFolder");
257 sf.value = selectedmbox;
260 var mb = document.getElementById("mailbox");
261 mb.value = selectedmbox;
263 SUGAR.inboundEmail.listDlg.hide();
265 function switchMsg() {
266 if(typeof(document.getElementById("sf_msg")) != "undefined") {
267 document.getElementById("sf_msg").innerHTML = "'.$msg.'";
268 var deletedFoldersList = document.getElementById("sf_deletedFoldersList");
269 deletedFoldersList.innerHTML = "'. $deletedFoldersList .'";
270 if (deletedFoldersList.innerHTML.length > 0) {
271 deletedFoldersList.style.display = "";
273 var selectedFoldersListObject = new Object();
274 var selectedFoldersListArray = document.getElementById("sf_selectedfoldersList").value.split(",");
275 for (var j = 0 ; j < selectedFoldersListArray.length ; j++) {
276 selectedFoldersListObject[selectedFoldersListArray[j]] = selectedFoldersListArray[j];
278 if (document.getElementById("sf_returnstatus").value == "1") {
279 var foldersList = document.getElementById("sf_foldersList").value;
280 var foldersArray = foldersList.split(",");
281 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
282 for (var i = 0 ; i < foldersArray.length ; i++) {
283 var opt = new Option(foldersArray[i], foldersArray[i]);
284 if (selectedFoldersListObject[foldersArray[i]] != null) {
287 inboundmailboxes.options.add(opt);
290 var selectdFoldersValue = document.getElementById("sf_selectedfoldersList").value;
291 var searchFieldValue = document.getElementById("sf_searchField").value;
292 if (selectdFoldersValue.length <= 0) {
293 if (searchFieldValue.length > 0) {
294 if (searchFieldValue == "trash") {
295 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
296 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
297 if ((inboundmailboxes.options[i].text.search(/trash/i) != -1) ||
298 (inboundmailboxes.options[i].text.search(/delete/i) != -1)) {
300 inboundmailboxes.options[i].selected = true;
305 if (searchFieldValue == "sent") {
306 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
307 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
308 if (inboundmailboxes.options[i].text.search(/sent/i) != -1) {
310 inboundmailboxes.options[i].selected = true;