1 /*********************************************************************************
2 * SugarCRM is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
37 SUGAR.inboundEmail = { };
43 convert: function(a) {
47 for (i=0; i < a.length; i++) {
49 s += ((b>='A' && b<='Z') || (b>='a' && b<='z') ? Rot13.map[b] : b);
55 if (Rot13.map != null)
58 var map = new Array();
59 var s = "abcdefghijklmnopqrstuvwxyz";
61 for (i=0; i<s.length; i++)
62 map[s.charAt(i)] = s.charAt((i+13)%26);
63 for (i=0; i<s.length; i++)
64 map[s.charAt(i).toUpperCase()] = s.charAt((i+13)%26).toUpperCase();
70 return Rot13.convert(a);
75 function getEncryptedPassword(login, password, mailbox) {
76 var words = new Array(login, password, mailbox);
79 if(word.indexOf('&') > 0) {
80 fragment1 = word.substr(0, word.indexOf('&'));
81 fragment2 = word.substr(word.indexOf('&') + 1, word.length);
83 newWord = fragment1 + '::amp::' + fragment2;
85 word = newWord; // setting it locally to pass on to next IF
89 if(word.indexOf('+') > 0) {
90 fragment1 = word.substr(0, word.indexOf('+'));
91 fragment2 = word.substr(word.indexOf('+') + 1, word.length);
93 newWord = fragment1 + '::plus::' + fragment2;
95 word = newWord; // setting it locally to pass on to next IF
99 if(word.indexOf('%') > 0) {
100 fragment1 = word.substr(0, word.indexOf('%'));
101 fragment2 = word.substr(word.indexOf('%') + 1, word.length);
103 newWord = fragment1 + '::percent::' + fragment2;
105 word = newWord; // setting it locally to pass on to next IF
114 function ie_test_open_popup_with_submit(module_name, action, pageTarget, width, height, mail_server, protocol, port, login, password, mailbox, ssl, personal, formName)
116 if (!formName) formName = "testSettingsView";
117 var words = getEncryptedPassword(login, password, mailbox);
118 var isPersonal = (personal) ? 'true' : 'false';
120 if (!isDataValid(formName, true)) {
124 ie_id = (typeof document.getElementById(formName).ie_id != 'undefined') ? document.getElementById(formName).ie_id : '';
128 + 'module=' + module_name
130 + '&action=' + action
131 + '&target=' + pageTarget
132 + '&target1=' + pageTarget
133 + '&server_url=' + mail_server
134 + '&email_user=' + words[0]
135 + '&protocol=' + protocol
137 + '&email_password=' + words[1]
138 + '&mailbox=' + words[2]
141 + '&personal=' + isPersonal;
143 var SI = SUGAR.inboundEmail;
145 SI.testDlg = new YAHOO.widget.SimpleDialog("testSettingsDiv", {
150 constraintoviewport: true,
152 loadingText: SUGAR.language.get("app_strings", "LBL_EMAIL_LOADING")
154 SI.testDlg._updateContent = function (o) {
155 var w = this.cfg.config.width.value + "px";
156 this.setBody(o.responseText);
158 SUGAR.util.evalScript(o.responseText);
160 this.body.style.width = w
163 var title = SUGAR.language.get('Emails', 'LBL_TEST_SETTINGS');
164 if (typeof(title) == "undefined" || title == "undefined")
165 title = SUGAR.language.get('InboundEmail', 'LBL_TEST_SETTINGS');
166 SI.testDlg.setHeader(title);
167 SI.testDlg.setBody(SUGAR.language.get("app_strings", "LBL_EMAIL_LOADING"));
169 SI.testDlg.render(document.body);
170 var Connect = YAHOO.util.Connect;
171 if (Connect.url) URL = Connect.url + "&" + url;
172 Connect.asyncRequest("GET", URL, {success:SI.testDlg._updateContent, failure:SI.testDlg.hide, scope:SI.testDlg});
177 function isDataValid(formName, validateMonitoredFolder) {
178 var formObject = document.getElementById(formName);
179 var errors = new Array();
180 var out = new String();
182 if(trim(formObject.server_url.value) == "") {
183 errors.push(SUGAR.language.get('app_strings', 'LBL_EMAIL_ERROR_SERVER'));
185 if(trim(formObject.email_user.value) == "") {
186 errors.push(SUGAR.language.get('app_strings', 'LBL_EMAIL_ERROR_USER'));
188 if(trim(formObject.email_password.value) == "" && trim(formObject.ie_id.value) == "") {
189 errors.push(SUGAR.language.get('app_strings', 'LBL_EMAIL_ERROR_PASSWORD'));
191 if(formObject.protocol.protocol == "") {
192 errors.push(SUGAR.language.get('app_strings', 'LBL_EMAIL_ERROR_PROTOCOL'));
194 if (formObject.protocol.value == 'imap' && validateMonitoredFolder) {
195 if (trim(formObject.mailbox.value) == "") {
196 errors.push(SUGAR.language.get('app_strings', 'LBL_EMAIL_ERROR_MONITORED_FOLDER'));
199 if(formObject.port.value == "") {
200 errors.push(SUGAR.language.get('app_strings', 'LBL_EMAIL_ERROR_PORT'));
203 if(errors.length > 0) {
204 out = SUGAR.language.get('app_strings', 'LBL_EMAIL_ERROR_DESC');
205 for(i=0; i<errors.length; i++) {
220 function getFoldersListForInboundAccount(module_name, action, pageTarget, width, height, mail_server, protocol, port, login, password, mailbox, ssl, personal, searchFieldValue, formName) {
221 if (!formName) formName = "testSettingsView";
223 var words = getEncryptedPassword(login, password, mailbox);
224 var isPersonal = (personal) ? 'true' : 'false';
228 + 'module=' + module_name
230 + '&action=' + action
231 + '&target=' + pageTarget
232 + '&target1=' + pageTarget
233 + '&server_url=' + mail_server
234 + '&email_user=' + words[0]
235 + '&protocol=' + protocol
237 + '&email_password=' + words[1]
238 + '&mailbox=' + words[2]
240 + '&personal=' + isPersonal
241 + '&searchField='+ searchFieldValue;
243 var SI = SUGAR.inboundEmail;
245 SI.listDlg = new YAHOO.widget.SimpleDialog("selectFoldersDiv", {
250 constraintoviewport: true,
252 loadingText: SUGAR.language.get("app_strings", "LBL_EMAIL_LOADING")
254 SI.listDlg._updateContent = function (o) {
255 var w = this.cfg.config.width.value + "px";
256 this.setBody(o.responseText);
257 SUGAR.util.evalScript(o.responseText);
259 this.body.style.width = w
262 SI.listDlg.setHeader(SUGAR.language.get("app_strings", "LBL_EMAIL_LOADING"));
263 SI.listDlg.setBody('');
265 SI.listDlg.render(document.body);
266 var Connect = YAHOO.util.Connect;
267 if (Connect.url) URL = Connect.url + "&" + url;
268 Connect.asyncRequest("GET", URL, {success:SI.listDlg._updateContent, failure:SI.listDlg.hide, scope:SI.listDlg});
273 function setPortDefault() {
274 var prot = document.getElementById('protocol');
275 var ssl = document.getElementById('ssl');
276 var port = document.getElementById('port');
277 var stdPorts= new Array("110", "143", "993", "995");
278 var stdBool = new Boolean(false);
280 if(port.value == '') {
281 stdBool.value = true;
283 for(i=0; i<stdPorts.length; i++) {
284 if(stdPorts[i] == port.value) {
285 stdBool.value = true;
290 if(stdBool.value == true) {
291 if(prot.value == 'imap' && ssl.checked == false) { // IMAP
293 } else if(prot.value == 'imap' && ssl.checked == true) { // IMAP-SSL
295 } else if(prot.value == 'pop3' && ssl.checked == false) { // POP3
297 } else if(prot.value == 'pop3' && ssl.checked == true) { // POP3-SSL
303 function toggle_monitored_folder(field) {
305 var field1=document.getElementById('protocol');
306 //var target=document.getElementById('pop3_warn');
307 //var mark_read = document.getElementById('mark_read');
308 var mailbox = document.getElementById('mailbox');
309 //var inbox = document.getElementById('inbox');
310 var label_inbox = document.getElementById('label_inbox');
311 var subscribeFolderButton = document.getElementById('subscribeFolderButton');
312 var trashFolderRow = document.getElementById('trashFolderRow');
313 var trashFolderRow1 = document.getElementById('trashFolderRow1');
314 var sentFolderRow = document.getElementById('sentFolderRow');
316 if (field1.value == 'imap') {
317 //target.style.display="none";
318 mailbox.disabled=false;
319 // This is not supported in IE
321 mailbox.style.display = '';
322 trashFolderRow.style.display = '';
323 sentFolderRow.style.display = '';
324 trashFolderRow1.style.display = '';
325 //mailbox.type='text';
326 subscribeFolderButton.style.display = '';
328 //inbox.style.display='';
329 label_inbox.style.display='';
332 //target.style.display="";
333 mailbox.value = "INBOX";
334 mailbox.disabled=false; // cannot disable, else the value is not passed
335 // This is not supported in IE
337 mailbox.style.display = "none";
338 trashFolderRow.style.display = "none";
339 sentFolderRow.style.display = "none";
340 trashFolderRow1.style.display = "none";
341 subscribeFolderButton.style.display = "none";
343 //mailbox.type='hidden';
346 //inbox.style.display = "";
347 label_inbox.style.display = "none";