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 $ie->email_user = $_REQUEST['email_user'];
114 $ie->server_url = $_REQUEST['server_url'];
115 $ie->port = $_REQUEST['port'];
116 $ie->protocol = $_REQUEST['protocol'];
117 //Bug 23083.Special characters in email password results in IMAP authentication failure
118 $ie->email_password = html_entity_decode($_REQUEST['email_password'], ENT_QUOTES);
119 $ie->email_password = str_rot13($ie->email_password);
120 //$ie->mailbox = $_REQUEST['mailbox'];
122 $ie->mailbox = 'INBOX';
125 $returnArray = $ie->getFoldersListForMailBox();
126 $foldersList = $returnArray['foldersList'];
127 if ($returnArray['status']) {
128 $msg = $returnArray['statusMessage'];
129 $requestMailBox = explode(",", $_REQUEST['mailbox']);
130 $foldersListArray = explode(",", $foldersList);
131 $deletedFoldersString = "";
133 if (!empty($requestMailBox) && !empty($foldersListArray)) {
134 foreach($requestMailBox as $mailbox) {
135 if (!in_array($mailbox, $foldersListArray)) {
137 $deletedFoldersString = $deletedFoldersString . " ,";
139 $deletedFoldersString = $deletedFoldersString . $mailbox;
144 if (!empty($deletedFoldersString)) {
145 $deletedFoldersList = $mod_strings['LBL_DELETED_FOLDERS_LIST'];
146 $deletedFoldersList = sprintf($deletedFoldersList, $deletedFoldersString);
149 $msg = $returnArray['statusMessage'];
154 ///////////////////////////////////////////////////////////////////////////////
156 ///////////////////////////////////////////////////////////////////////////////
158 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0">
168 if (!empty($subdcriptionFolderHelp)) {
178 <td>'.$subdcriptionFolderHelp.'
186 <div id="sf_deletedFoldersList" style="display:none;">
187 '.$deletedFoldersList.'
195 <select '.$multipleString.' size="12" name="inboundmailboxes" id="sf_inboundmailboxes">
209 <input type="button" style="" class="button" value="'.$app_strings['LBL_DONE_BUTTON_LABEL'].'" onclick="setMailbox();">
210 <input type="button" class="button" value="'.$app_strings['LBL_EMAIL_CANCEL'].'" onclick="SUGAR.inboundEmail.listDlg.hide()">
222 ///////////////////////////////////////////////////////////////////////////////
224 ///////////////////////////////////////////////////////////////////////////////
225 //// COMPLETE RENDERING OF THE POPUP
226 echo '<input type="hidden" id="sf_returnstatus" name="returnstatus" value="'. $returnArray['status'] .'">';
227 echo '<input type="hidden" id="sf_foldersList" name="foldersList" value="'. $foldersList .'">';
228 echo '<input type="hidden" id="sf_selectedfoldersList" name="selectedfoldersList" value="'. implode(",", $requestMailBox) .'">';
229 echo '<input type="hidden" id="sf_searchField" name="searchField" value="'. $searchField .'">';
232 <script type="text/javascript">
233 SUGAR.inboundEmail.listDlg.setHeader("'.$title.'");
234 function setMailbox(box) {
235 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
236 var selectedmbox = "";
238 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
239 if (inboundmailboxes.options[i].selected) {
241 selectedmbox = selectedmbox + ",";
243 selectedmbox = selectedmbox + inboundmailboxes.options[i].value;
247 var searchFieldValue = document.getElementById("sf_searchField").value;
248 if (searchFieldValue.length > 0) {
249 if (searchFieldValue == "trash") {
250 var tf = document.getElementById("trashFolder");
251 tf.value = selectedmbox;
252 } else if(searchFieldValue == "sent") {
253 var sf = document.getElementById("sentFolder");
254 sf.value = selectedmbox;
257 var mb = document.getElementById("mailbox");
258 mb.value = selectedmbox;
260 SUGAR.inboundEmail.listDlg.hide();
262 function switchMsg() {
263 if(typeof(document.getElementById("sf_msg")) != "undefined") {
264 document.getElementById("sf_msg").innerHTML = "'.$msg.'";
265 var deletedFoldersList = document.getElementById("sf_deletedFoldersList");
266 deletedFoldersList.innerHTML = "'. $deletedFoldersList .'";
267 if (deletedFoldersList.innerHTML.length > 0) {
268 deletedFoldersList.style.display = "";
270 var selectedFoldersListObject = new Object();
271 var selectedFoldersListArray = document.getElementById("sf_selectedfoldersList").value.split(",");
272 for (var j = 0 ; j < selectedFoldersListArray.length ; j++) {
273 selectedFoldersListObject[selectedFoldersListArray[j]] = selectedFoldersListArray[j];
275 if (document.getElementById("sf_returnstatus").value == "1") {
276 var foldersList = document.getElementById("sf_foldersList").value;
277 var foldersArray = foldersList.split(",");
278 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
279 for (var i = 0 ; i < foldersArray.length ; i++) {
280 var opt = new Option(foldersArray[i], foldersArray[i]);
281 if (selectedFoldersListObject[foldersArray[i]] != null) {
284 inboundmailboxes.options.add(opt);
287 var selectdFoldersValue = document.getElementById("sf_selectedfoldersList").value;
288 var searchFieldValue = document.getElementById("sf_searchField").value;
289 if (selectdFoldersValue.length <= 0) {
290 if (searchFieldValue.length > 0) {
291 if (searchFieldValue == "trash") {
292 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
293 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
294 if ((inboundmailboxes.options[i].text.search(/trash/i) != -1) ||
295 (inboundmailboxes.options[i].text.search(/delete/i) != -1)) {
297 inboundmailboxes.options[i].selected = true;
302 if (searchFieldValue == "sent") {
303 var inboundmailboxes = document.getElementById("sf_inboundmailboxes");
304 for (var i = 0 ; i < inboundmailboxes.options.length ; i++) {
305 if (inboundmailboxes.options[i].text.search(/sent/i) != -1) {
307 inboundmailboxes.options[i].selected = true;