[564] | 1 | |
---|
| 2 | function charCounter(form) |
---|
| 3 | { |
---|
| 4 | if (form.value.length >= 300) |
---|
| 5 | { |
---|
[3741] | 6 | alert(get_lang("You have exceeded the number of allowed characters")); |
---|
[564] | 7 | return false; |
---|
| 8 | } |
---|
[139] | 9 | } |
---|
[197] | 10 | |
---|
[92] | 11 | function cfilter(){ |
---|
[2] | 12 | |
---|
[3018] | 13 | this.criticalError = false; |
---|
[2] | 14 | this.mode_in = ""; |
---|
| 15 | this.rulest = new Array; |
---|
[564] | 16 | this.rulesVoip = new Array; |
---|
[197] | 17 | this.out_officeR = ""; |
---|
| 18 | this.out_officeF = false; |
---|
[2] | 19 | this.email_deny = new Array; |
---|
| 20 | this.ac_form = ""; |
---|
| 21 | this.ind = ""; |
---|
| 22 | this.email_deny = new Array; |
---|
[197] | 23 | this.email_ld = ""; |
---|
[2] | 24 | this.values = new Array("", |
---|
| 25 | ",select_size=1", |
---|
| 26 | ",select_rules=1", |
---|
[3133] | 27 | ",select_size=1,select_rules=1", |
---|
| 28 | ",checkBox2", |
---|
[2] | 29 | ",checkBox2,select_size=1", |
---|
| 30 | ",ckeckBox1,checkBox2,select_size=1", |
---|
[3133] | 31 | ",checkBox2,select_rules=1", |
---|
| 32 | ",checkBox2,select_size=1,select_rules=1"); |
---|
[2] | 33 | |
---|
| 34 | } |
---|
[564] | 35 | |
---|
[2] | 36 | |
---|
[3018] | 37 | cfilter.prototype.load_rules = function(posHandler, param) |
---|
[564] | 38 | { |
---|
[2] | 39 | var _this = this; |
---|
[564] | 40 | var cont1 = parseInt(0); |
---|
| 41 | var cont2 = parseInt(0); |
---|
[3018] | 42 | |
---|
[564] | 43 | if( _this.rulest.length == 0 ) |
---|
| 44 | { |
---|
| 45 | var handler_sieve = function(data) |
---|
| 46 | { |
---|
[3018] | 47 | if (data.toString().indexOf('Error:') == 0) |
---|
| 48 | { |
---|
| 49 | _this.criticalError = true; |
---|
| 50 | alert(get_lang('The filters service is out of service, try again later...')); |
---|
| 51 | } |
---|
| 52 | else |
---|
| 53 | try{ |
---|
[2] | 54 | if(data.rule.length > 0){ |
---|
[564] | 55 | for(var i=0 ; i < data.rule.length; i++) |
---|
| 56 | { |
---|
| 57 | var fields = data.rule[i].split("&&"); |
---|
| 58 | if( fields[6] == 'notify' && fields[7] == preferences.voip_email_redirect ) |
---|
| 59 | _this.rulesVoip[cont1++] = data.rule[i]; |
---|
| 60 | else |
---|
| 61 | _this.rulest[cont2++] = data.rule[i]; |
---|
[2] | 62 | } |
---|
| 63 | } |
---|
[197] | 64 | _this.out_officeR = data.vacation[0]; |
---|
| 65 | _this.out_officeR = _this.out_officeR ? trim(_this.out_officeR.toString().replace("\n","")) : ""; |
---|
[2] | 66 | if(data.mode.length > 0){_this.mode_in = data.mode[0];} |
---|
[3018] | 67 | } |
---|
| 68 | catch(e){ |
---|
| 69 | _this.criticalError = true; |
---|
| 70 | alert(get_lang('The filters service is out of service, try again later...')); |
---|
| 71 | } |
---|
| 72 | if (typeof(posHandler) == 'function') |
---|
| 73 | posHandler(param); |
---|
[2] | 74 | } |
---|
| 75 | if(Element('form_status') != null) |
---|
| 76 | Element('form_status').innerHTML = "<span style='background:#cc4444;'> <font color='WHITE'>Aguarde...</font> </span>"; |
---|
| 77 | cExecute("$this.ScriptS.init_a",handler_sieve); |
---|
[197] | 78 | _this.get_email(); |
---|
| 79 | } |
---|
[2] | 80 | } |
---|
| 81 | |
---|
| 82 | cfilter.prototype.form_m = function(){ |
---|
| 83 | Element('form_body').innerHTML = ""; |
---|
| 84 | Element('form_buttons').style.display = ''; |
---|
| 85 | filters.mount_list(); |
---|
| 86 | this.ac_form = ""; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | cfilter.prototype.form_out = function(){ |
---|
| 90 | Element('form_body').innerHTML = ""; |
---|
| 91 | Element('form_body').innerHTML = this.forms_(); |
---|
| 92 | Element('div_vacation').style.display = ""; |
---|
| 93 | this.ac_form = "old_out"; |
---|
| 94 | this.r_rules_out(); |
---|
| 95 | } |
---|
| 96 | |
---|
[564] | 97 | cfilter.prototype.form_r = function(pos,type) |
---|
| 98 | { |
---|
[2] | 99 | Element('form_body').innerHTML = ""; |
---|
| 100 | Element('form_body').innerHTML = this.forms_(); |
---|
[564] | 101 | this.ind = pos; |
---|
| 102 | |
---|
| 103 | if( type === 'voip') |
---|
| 104 | { |
---|
| 105 | this.ac_form = "old_voip"; |
---|
| 106 | Element('div_voipFilter').style.display = ""; |
---|
| 107 | this.r_rules_form(pos, type); |
---|
| 108 | } |
---|
| 109 | else |
---|
| 110 | { |
---|
| 111 | this.ac_form = "old_rule"; |
---|
| 112 | Element('div_rule').style.display = ""; |
---|
| 113 | this.r_rules_form(pos, type); |
---|
| 114 | } |
---|
[2] | 115 | } |
---|
| 116 | |
---|
[564] | 117 | cfilter.prototype.get_email = function() |
---|
| 118 | { |
---|
[2] | 119 | var _this = this; |
---|
[564] | 120 | var handler_get_email = function(data) |
---|
| 121 | { |
---|
[197] | 122 | _this.email_ld = data ? data : ""; |
---|
[2] | 123 | } |
---|
[197] | 124 | cExecute("$this.user.get_email",handler_get_email); |
---|
[2] | 125 | } |
---|
| 126 | |
---|
[564] | 127 | cfilter.prototype.sel_boxes = function() |
---|
| 128 | { |
---|
[2] | 129 | var nm_folders = tree_folders.getNodesList(cyrus_delimiter); |
---|
| 130 | if(document.getElementById("select_mailboxes") != null){ |
---|
| 131 | var sel_nm = document.getElementById("select_mailboxes"); |
---|
| 132 | if(sel_nm.length > 0 ){ |
---|
| 133 | for(var i=0; i < sel_nm.options.length; i++){ |
---|
| 134 | sel_nm.options[i] = null; |
---|
| 135 | i--; |
---|
| 136 | } |
---|
| 137 | } |
---|
[689] | 138 | for(var i=0; i < nm_folders.length; i++){ |
---|
| 139 | if(nm_folders[i].id != "root" && !proxy_mensagens.is_local_folder(nm_folders[i].id)){ |
---|
[2] | 140 | var opt = new Option(nm_folders[i].caption,nm_folders[i].id,false,true); |
---|
| 141 | sel_nm[sel_nm.length] = opt; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | sel_nm[0].selected = true; |
---|
| 145 | } |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | cfilter.prototype.box_select = function(param){ |
---|
| 149 | var aux = this.BoxSelection[param].split(","); |
---|
| 150 | var ele1 = document.getElementById(aux[0]); |
---|
| 151 | var ele2 = document.getElementById(aux[1]); |
---|
| 152 | var noption = ""; |
---|
| 153 | if(param == 0 || param == 1){ |
---|
| 154 | if(ele1.selectedIndex != -1){ |
---|
| 155 | noption = new Option(ele1.value,ele1.value,false,false); |
---|
| 156 | ele2.options[ele2.length] = noption; |
---|
| 157 | ele1.options[ele1.selectedIndex] = null; |
---|
| 158 | ele1.selectedIndex = 0; |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | } |
---|
| 162 | |
---|
[564] | 163 | cfilter.prototype.r_rules_form = function(ind, type) |
---|
| 164 | { |
---|
| 165 | var fields = new Array; |
---|
| 166 | var _this = this; |
---|
[2] | 167 | |
---|
| 168 | // hide buttons |
---|
| 169 | Element('form_buttons').style.display = 'none'; |
---|
| 170 | |
---|
[564] | 171 | if( type === 'voip') |
---|
| 172 | { |
---|
| 173 | fields = _this.rulesVoip[ind].split("&&"); |
---|
| 174 | document.getElementById("field9").value = fields[5]; |
---|
[2] | 175 | } |
---|
[564] | 176 | else |
---|
| 177 | { |
---|
| 178 | this.sel_boxes(); |
---|
| 179 | if(this.rulest.length == 0){ |
---|
| 180 | return false; |
---|
[2] | 181 | } |
---|
[564] | 182 | fields = _this.rulest[ind].split("&&"); |
---|
| 183 | document.getElementById("field1").value = fields[3]; |
---|
| 184 | document.getElementById("field2").value = fields[4]; |
---|
| 185 | document.getElementById("field3").value = fields[5]; |
---|
| 186 | document.getElementById("field4").value = fields[11]; |
---|
| 187 | |
---|
| 188 | switch(fields[6]){ |
---|
| 189 | case "folder": |
---|
| 190 | document.getElementById("radio1").checked = true; |
---|
| 191 | var name_mb = fields[7]; |
---|
| 192 | var sel_mb = document.getElementById("select_mailboxes"); |
---|
| 193 | for(var i=0; i < sel_mb.options.length; i++){if((sel_mb.options[i].value) == name_mb){sel_mb.options[i].selected = true;}} |
---|
| 194 | break; |
---|
| 195 | case "address": |
---|
| 196 | document.getElementById("radio2").checked = true; |
---|
| 197 | document.getElementById("field5").value = fields[7]; |
---|
| 198 | break; |
---|
| 199 | case "reject": |
---|
| 200 | document.getElementById("radio3").checked = true; |
---|
| 201 | var text0 = fields[7].split("\\n"); |
---|
| 202 | for(var i=0; i < text0.length; i++){document.getElementById("field6").value += text0[i] + "\n";} |
---|
| 203 | break; |
---|
| 204 | case "discard": |
---|
| 205 | document.getElementById("radio4").checked = true; |
---|
| 206 | break; |
---|
[3441] | 207 | case "flagged": |
---|
| 208 | document.getElementById("radio5").checked = true; |
---|
| 209 | break; |
---|
[2] | 210 | } |
---|
[564] | 211 | var mark_values = this.values[fields[8]].split(","); |
---|
| 212 | for(var i=0; i < mark_values.length; i++){ |
---|
[3133] | 213 | if( mark_values[i] == "checkBox2"){ |
---|
[564] | 214 | document.getElementById(mark_values[i]).checked = true; |
---|
| 215 | } |
---|
| 216 | if( mark_values[i] == "select_size=1" || mark_values[i] == "select_rules=1"){ |
---|
| 217 | var mark_val = mark_values[i].split("="); |
---|
| 218 | document.getElementById(mark_val[0]).options[mark_val[1]].selected = true; |
---|
| 219 | } |
---|
| 220 | } |
---|
[2] | 221 | } |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | cfilter.prototype.r_rules_out = function(){ |
---|
| 225 | |
---|
| 226 | var _this = this; |
---|
| 227 | if(_this.out_officeR.length == 0){ |
---|
| 228 | return false; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | // hide buttons |
---|
| 232 | Element('form_buttons').style.display = 'none'; |
---|
| 233 | |
---|
[197] | 234 | var aux = _this.out_officeR.split("&&"); |
---|
[2] | 235 | var days = aux[1]; |
---|
| 236 | var emails = aux[2]; |
---|
| 237 | var mens = aux[3]; |
---|
| 238 | var p_emails = new Array; |
---|
| 239 | var d_emails = new Array; |
---|
| 240 | |
---|
| 241 | var p_aux = emails.split(", "); |
---|
| 242 | for(var i=0; i < p_aux.length; i++){ |
---|
| 243 | p_emails[i] = p_aux[i].substr(0,(p_aux[i].length - 1)); |
---|
| 244 | p_emails[i] = p_emails[i].substr(1,(p_aux[i].length)); |
---|
| 245 | } |
---|
| 246 | for(var i=0; i < _this.email_ld.length; i++){ |
---|
| 247 | d_emails[i] = _this.email_ld[i]; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | diff = function(vet, comp){ |
---|
| 251 | var sel1 = new Array; |
---|
| 252 | for(var i=0; i < vet.length; i++){ |
---|
| 253 | for(var j=0; j < comp.length; j++){ |
---|
| 254 | if(vet[i] == comp[j]){ |
---|
| 255 | comp.splice(j,1); |
---|
| 256 | j--; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | }; |
---|
| 261 | diff(p_emails,d_emails); |
---|
| 262 | var text = mens.split("\\n"); |
---|
| 263 | for(var i=0; i < text.length; i++){document.getElementById("field8").value += text[i] + " ";} |
---|
| 264 | for(var i=0; i < _this.email_ld.length; i++){ |
---|
| 265 | d_emails[i] = _this.email_ld[i]; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | } |
---|
| 269 | |
---|
[325] | 270 | /* |
---|
| 271 | * Corrige bug 65, solução: desabilitar radio3 e field6 e desmarcar radio3 (ação de rejeição) |
---|
| 272 | * quando a caixa de seleção para manter o e-mail na caixa de entrada do usuário for selecionada |
---|
| 273 | */ |
---|
[3026] | 274 | cfilter.prototype.disable_radio = function() |
---|
[564] | 275 | { |
---|
[3026] | 276 | radio4 = Element('radio4'); |
---|
[325] | 277 | radio3 = Element('radio3'); |
---|
[3026] | 278 | cb2 = Element('checkBox2'); |
---|
[325] | 279 | field6 = Element('field6'); |
---|
| 280 | |
---|
[564] | 281 | if (cb2.checked) |
---|
| 282 | { |
---|
[325] | 283 | radio3.disabled = true; |
---|
[3026] | 284 | radio4.disabled = true; |
---|
[325] | 285 | field6.disabled = true; |
---|
| 286 | |
---|
[564] | 287 | if (radio3.checked) |
---|
| 288 | { |
---|
[325] | 289 | radio3.checked = false; |
---|
| 290 | } |
---|
| 291 | } |
---|
[564] | 292 | else |
---|
| 293 | { |
---|
[325] | 294 | radio3.disabled = false; |
---|
[3026] | 295 | radio4.disabled = true; |
---|
[325] | 296 | field6.disabled = false; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | } |
---|
| 300 | |
---|
[564] | 301 | cfilter.prototype.forms_ = function() |
---|
| 302 | { |
---|
| 303 | var form = ""; |
---|
| 304 | form = "<div id='div_rule' style='display:none'><table id='table_rule' border='0' cellpading='0' cellspacing='0' width='100%'>"+ |
---|
[3026] | 305 | "<tr><td colspan='2'><b>"+get_lang("Criteria")+":</b></td></tr><tr>"+ |
---|
| 306 | "<td rowspan='4' width='20%'>"+get_lang('Find items')+":<br><select id='select_rules' name='select_rules'>"+ |
---|
| 307 | "<option value='1'>"+get_lang("If any criterion is met")+"</option><option value='0'>"+get_lang("If all criteria is met")+"</option>"+ |
---|
| 308 | "</select></td><td>"+get_lang('The field \"%1\" of the message it contains',get_lang('From'))+".: <input type='text' id='field1' name='field1' size='35' maxlength='200'></td>"+ |
---|
[564] | 309 | "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('To'))+".: <input type='text' id='field2' name='field2' size='35' maxlength='200'></td>"+ |
---|
| 310 | "</tr><tr><td>"+get_lang('The field \"%1\" of the message it contains', get_lang('Subject'))+".: <input type='text' id='field3' name='field3' size='35' maxlength='200'></td>"+ |
---|
| 311 | "</tr><tr><td>"+get_lang('The size of the message is')+".:  <select id='select_size' name='select_size'>"+ |
---|
[3438] | 312 | "<option value='0'>"+get_lang("Less than")+"</option><option value='1'>"+get_lang("Greater than")+"</option>"+ |
---|
[564] | 313 | "</select> <input type='text' id='field4' name='field4' size='8' maxlength='8'> Kb</td>"+ |
---|
[3026] | 314 | "</tr><tr><td colspan='2'><hr size='1' width='100%'><b>"+get_lang("Action")+":</b></td></tr>"+ |
---|
[564] | 315 | "</table><table id='table_rule1' border='0' cellpading='0' cellspacing='0' width='100%'>"+ |
---|
[3026] | 316 | "<tr><td colspan='2'><input type='checkBox' id='checkBox2' onclick='filter.disable_radio();' name='checkb'>"+get_lang('Keep a copy of the message at your Inbox')+ "</td><tr>"+ |
---|
| 317 | "<tr><td width='50%'><input type='radio' id='radio1' name='radio' value='folder'>"+get_lang('Store at')+".:</td>"+ |
---|
[564] | 318 | "<td width='50%'><select id='select_mailboxes' name='select_mailboxes'></select></td>"+ |
---|
| 319 | "</tr><tr><td width='50%'><input type='radio' id='radio2' name='radio' value='address'>"+get_lang('Forward to the address')+".:</td>"+ |
---|
| 320 | "<td width='50%'><input type='text' id='field5' name='field5' size='35' maxlength='70'></td>"+ |
---|
| 321 | "</tr><tr><td width='50%'><input type='radio' id='radio3' name='radio' value='reject'>"+get_lang('Send a rejection message')+".:</td>"+ |
---|
| 322 | "<td width='50%'><textarea id='field6' onkeypress='return charCounter(this);' name='field6' rows='3' cols='25'></textarea></td>"+ |
---|
[3441] | 323 | "</tr><tr id='tr_radio4'><td colspan='2'><input type='radio' id='radio4' name='radio' value='discard'>"+get_lang('Erase the message')+"</td>"+ |
---|
| 324 | "</tr><tr id='tr_radio5'><td colspan='2'><input type='radio' id='radio5' name='radio' value='important'>"+get_lang('Flag as important')+"</td>"+ |
---|
[564] | 325 | "</tr></table></div><div id='div_vacation' style='display:none'>"+ |
---|
| 326 | "<table id='table_vacation' border='0' cellpading='0' cellspacing='0' width='100%'>"+ |
---|
| 327 | "<tr><td colspan='3'><br><b>"+get_lang('out office')+"</b></td></tr>"+ |
---|
| 328 | //"<tr><td colspan='3'><br>"+get_lang('Subject')+".: <input type='text' id='field7' name='field7' size='35' maxlength='200'/></td></tr>"+ |
---|
| 329 | "<tr><td colspan='3'><br>"+get_lang('With the following message')+".:</td>"+ |
---|
| 330 | "</tr><tr><td colspan='3'><textarea id='field8' onkeypress='return charCounter(this);' rows='8' cols='50'></textarea></td></tr></table></div>" + |
---|
| 331 | "<div id='div_voipFilter' style='display:none'>" + |
---|
| 332 | "<br/><table id='table_voipFilter'>" + |
---|
| 333 | "<tr><td>"+get_lang("Type the subject of the message for receiving a phone warning")+" .:"+ |
---|
| 334 | "</td></tr><tr><td><input type='text' id='field9' size='50' maxlength='200'>" + |
---|
| 335 | "</td></tr><br/></table></div>" + |
---|
| 336 | "<span align='right'><input type='button' value="+get_lang("Back")+" onclick='filter.form_m()'></span>"+ |
---|
| 337 | "<span align='right'><input type='button' value="+get_lang("Save")+" onclick='filter.saved_rules()'></span>"; |
---|
[2] | 338 | return form; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | cfilter.prototype.enabled_disabled = function(param){ |
---|
| 342 | |
---|
| 343 | // Rules |
---|
| 344 | if(Element("rule_0") != null){ |
---|
| 345 | for(var i=0; i < this.rulest.length; i++){ |
---|
| 346 | if(Element("rule_"+i).checked){ |
---|
| 347 | var aux_rul = this.rulest[i].split("&&"); |
---|
| 348 | if(aux_rul[2] != param){ |
---|
| 349 | aux_rul[2] = param; |
---|
| 350 | var rl = ""; |
---|
| 351 | for(var j=0; j < aux_rul.length; j++){ |
---|
| 352 | rl += aux_rul[j] + "&&"; |
---|
| 353 | } |
---|
| 354 | rl = rl.substr(0,(rl.length - 2)); |
---|
| 355 | this.rulest[i] = rl; |
---|
| 356 | } |
---|
| 357 | } |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | // Out Office |
---|
| 361 | if(Element("out_0") != null){ |
---|
| 362 | if(Element("out_0").checked){ |
---|
[197] | 363 | var aux_out = this.out_officeR.split("&&"); |
---|
[2] | 364 | if(param == "ENABLED") |
---|
| 365 | aux_out[4] = "on "; |
---|
| 366 | else |
---|
| 367 | aux_out[4] = "off"; |
---|
| 368 | var out = ""; |
---|
| 369 | for(var i=0; i < aux_out.length; i++){ |
---|
| 370 | out += aux_out[i] + "&&"; |
---|
| 371 | } |
---|
| 372 | out = out.substr(0,(out.length - 2)); |
---|
[197] | 373 | this.out_officeR = out; |
---|
[2] | 374 | } |
---|
| 375 | } |
---|
[564] | 376 | |
---|
| 377 | // Voip |
---|
| 378 | if(Element("voip_rule_0") != null){ |
---|
| 379 | for(var i=0; i < this.rulesVoip.length; i++){ |
---|
| 380 | if(Element("voip_rule_"+i).checked){ |
---|
| 381 | var aux_rul = this.rulesVoip[i].split("&&"); |
---|
| 382 | if(aux_rul[2] != param){ |
---|
| 383 | aux_rul[2] = param; |
---|
| 384 | var rl = ""; |
---|
| 385 | for(var j=0; j < aux_rul.length; j++){ |
---|
| 386 | rl += aux_rul[j] + "&&"; |
---|
| 387 | } |
---|
| 388 | rl = rl.substr(0,(rl.length - 2)); |
---|
| 389 | this.rulesVoip[i] = rl; |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | } |
---|
| 394 | |
---|
[2] | 395 | this.reload_rules(); |
---|
| 396 | } |
---|
| 397 | |
---|
[3018] | 398 | cfilter.prototype.new_rule = function(email){ |
---|
[2] | 399 | |
---|
[3018] | 400 | var createFilter = function (param){ |
---|
| 401 | if (filter.criticalError){ |
---|
| 402 | alert(get_lang('The filters service is out of service, try again later...')); |
---|
| 403 | return false; |
---|
| 404 | } |
---|
| 405 | if(filter.rulest.length > 0){ |
---|
| 406 | var blockedReg = new RegExp('#rule&&[0-9]+&&ENABLED&&'+param+'&&&&&&discard&&&&0&&&&&&0'); |
---|
| 407 | for(var i=0 ; i < filter.rulest.length; i++){ |
---|
| 408 | if(blockedReg.test(filter.rulest[i])){ |
---|
| 409 | alert(get_lang("Sender blocked")+"!"); |
---|
| 410 | return false; |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | } |
---|
| 414 | if(confirm(get_lang("Do you want to block this e-mail?"))){ |
---|
| 415 | new_r = "&&ENABLED&&" + param + "&&&&&&discard&&&&0&&&&&&0"; |
---|
| 416 | //setTimeout("filter.e_newrule('" + new_r + "')",2000); |
---|
| 417 | if (filter.e_newrule(new_r)){ |
---|
| 418 | filter.email_deny.push(new_r); |
---|
| 419 | write_msg(get_lang("The sender was blocked")); |
---|
| 420 | }else |
---|
| 421 | write_msg(get_lang("You have reached the maximum number of rules")); |
---|
| 422 | } |
---|
| 423 | }; |
---|
| 424 | if ( filter.rulest.length > 0 ) |
---|
| 425 | createFilter(email); |
---|
| 426 | else |
---|
| 427 | this.load_rules( createFilter, email ); |
---|
| 428 | } |
---|
[2] | 429 | |
---|
[564] | 430 | cfilter.prototype.e_newrule = function(nw_rule) |
---|
| 431 | { |
---|
[2] | 432 | |
---|
| 433 | var new_rl = ""; |
---|
[246] | 434 | if (this.rulest.length >= rules_limit) |
---|
| 435 | return false; |
---|
| 436 | |
---|
[2] | 437 | if(this.rulest.length == 0){ |
---|
| 438 | new_rl = "#rule&&1" + nw_rule; |
---|
| 439 | }else{ |
---|
| 440 | var aux = this.rulest[this.rulest.length -1 ].split("&&"); |
---|
| 441 | new_rl = "#rule&&" + (parseInt(aux[1]) + parseInt(2)) + nw_rule; |
---|
| 442 | } |
---|
| 443 | this.rulest.push(new_rl); |
---|
| 444 | this.saved_all(); |
---|
[246] | 445 | return true; |
---|
[2] | 446 | } |
---|
| 447 | |
---|
| 448 | cfilter.prototype.delete_r = function(){ |
---|
| 449 | |
---|
| 450 | // rule |
---|
| 451 | var _this = this; |
---|
| 452 | if(Element("rule_0") != null){ |
---|
| 453 | for(var i=0; i < _this.rulest.length; i++){ |
---|
| 454 | if(Element("rule_"+i).checked){_this.rulest[i] = "delete";} |
---|
| 455 | } |
---|
| 456 | for(var i=0; i < _this.rulest.length; i++){ |
---|
| 457 | if(_this.rulest[i] == "delete"){_this.rulest.splice(i,1);i--;} |
---|
| 458 | } |
---|
| 459 | } |
---|
| 460 | |
---|
| 461 | if(_this.rulest.length > 0){ |
---|
| 462 | var cont = parseInt(1); |
---|
| 463 | for(var i=0; i < _this.rulest.length ; i++){ |
---|
| 464 | var n_rulest = _this.rulest[i].split("&&"); |
---|
| 465 | n_rulest[1] = cont; |
---|
| 466 | cont = cont + parseInt(2); |
---|
| 467 | var aux = ""; |
---|
| 468 | for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";} |
---|
| 469 | aux = aux.substr(0,(aux.length - 2)); |
---|
| 470 | _this.rulest[i] = aux; |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | // out office |
---|
| 474 | if(Element("out_0") != null){ |
---|
[206] | 475 | if(Element("out_0").checked){ |
---|
| 476 | _this.out_officeR =''; |
---|
| 477 | _this.out_officeF = false; |
---|
| 478 | //Save outoffice in prefs: |
---|
[271] | 479 | connector.loadScript("preferences"); |
---|
[206] | 480 | prefe.save("outoffice", _this.out_officeF); |
---|
| 481 | } |
---|
[2] | 482 | } |
---|
[564] | 483 | |
---|
| 484 | // Voip |
---|
| 485 | if(Element("voip_rule_0") != null){ |
---|
| 486 | for(var i=0; i < _this.rulesVoip.length; i++){ |
---|
| 487 | if(Element("voip_rule_"+i).checked){_this.rulesVoip[i] = "delete";} |
---|
| 488 | } |
---|
| 489 | for(var i=0; i < _this.rulesVoip.length; i++){ |
---|
| 490 | if(_this.rulesVoip[i] == "delete"){_this.rulesVoip.splice(i,1);i--;} |
---|
| 491 | } |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | if(_this.rulesVoip.length > 0){ |
---|
| 495 | var cont = parseInt(1); |
---|
| 496 | for(var i=0; i < _this.rulesVoip.length ; i++){ |
---|
| 497 | var n_rulest = _this.rulesVoip[i].split("&&"); |
---|
| 498 | n_rulest[1] = cont; |
---|
| 499 | cont = cont + parseInt(2); |
---|
| 500 | var aux = ""; |
---|
| 501 | for(var j=0; j < n_rulest.length; j++){aux += n_rulest[j] + "&&";} |
---|
| 502 | aux = aux.substr(0,(aux.length - 2)); |
---|
| 503 | _this.rulesVoip[i] = aux; |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | |
---|
[2] | 507 | _this.reload_rules(); |
---|
| 508 | } |
---|
| 509 | |
---|
[564] | 510 | cfilter.prototype.reload_rules = function() |
---|
| 511 | { |
---|
[2] | 512 | this.saved_all(); |
---|
| 513 | Element('form_body').innerHTML = ""; |
---|
| 514 | this.load_rules(); |
---|
[564] | 515 | |
---|
| 516 | if(this.out_officeF) |
---|
| 517 | { |
---|
[197] | 518 | write_msg(get_lang("Attention, you are in out of office mode."), true); |
---|
[564] | 519 | }else{ |
---|
[197] | 520 | clean_msg(); |
---|
| 521 | this.out_officeF = false; |
---|
| 522 | } |
---|
[2] | 523 | filters.mount_list(); |
---|
| 524 | } |
---|
| 525 | |
---|
[3407] | 526 | cfilter.prototype.forwardAddressValidation = function(addr) { |
---|
| 527 | domains = sieve_forward_domains.replace(/\s/g, "").replace(/\./g, "\\.").replace(/,/g, "|"); |
---|
| 528 | domainRegexp = new RegExp("(" + domains +")$"); |
---|
| 529 | return domainRegexp.test(addr); |
---|
| 530 | } |
---|
| 531 | |
---|
[2] | 532 | cfilter.prototype.saved_rules = function(){ |
---|
| 533 | |
---|
| 534 | var mount_rule = ""; |
---|
| 535 | var form = this.ac_form.split("_"); |
---|
| 536 | var n_rule = ""; |
---|
| 537 | |
---|
[564] | 538 | if(form[1] == "rule") |
---|
| 539 | { |
---|
[2] | 540 | mount_rule = "#rule&&"; |
---|
[564] | 541 | if(form[0] == "new") |
---|
| 542 | { |
---|
[2] | 543 | n_rule = "1&&"; |
---|
[564] | 544 | if(this.rulest.length > 0) |
---|
| 545 | { |
---|
[2] | 546 | aux = this.rulest[this.rulest.length - parseInt(1)].split("&&"); |
---|
| 547 | n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&"; |
---|
| 548 | } |
---|
| 549 | mount_rule += n_rule + "ENABLED&&"; |
---|
[564] | 550 | } |
---|
| 551 | else |
---|
| 552 | { |
---|
[2] | 553 | n_rule = this.rulest[this.ind].split("&&"); |
---|
| 554 | mount_rule += n_rule[1] + "&&"; |
---|
| 555 | mount_rule += n_rule[2] + "&&"; |
---|
| 556 | } |
---|
| 557 | |
---|
[3775] | 558 | if ( |
---|
| 559 | ( /[^\x00-\x80]/.test( Element("field1").value ) || /[^\x00-\x80]/.test( Element("field2").value ) || /[^\x00-\x80]/.test( Element("field3").value ) ) |
---|
| 560 | && ( ! confirm( get_lang ( 'Your rule contains any accented character. The filter may not work. Do you wish to continue?' ) ) ) |
---|
| 561 | ) return false; |
---|
| 562 | |
---|
[41] | 563 | if(LTrim(Element("field1").value) == "" && LTrim(Element("field2").value) == "" && LTrim(Element("field3").value) == "" && Element("field4").value == "") |
---|
| 564 | { |
---|
[1546] | 565 | alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!")); |
---|
[2] | 566 | return false; |
---|
| 567 | } |
---|
[41] | 568 | |
---|
| 569 | if((LTrim(Element("field1").value).length <= 3) && (LTrim(Element("field2").value).length <= 3) && (LTrim(Element("field3").value).length <= 3 && Element("field4").value == "")){ |
---|
[1546] | 570 | alert(get_lang("Define some criterion to the fields Sender, To and Subject with more than 3 characters!")); |
---|
[2] | 571 | return false; |
---|
| 572 | } |
---|
| 573 | |
---|
[3837] | 574 | if (LTrim(Element("field4").value).length > 0){ |
---|
| 575 | var isNumero = /^\d+$/.test(Element("field4").value); |
---|
| 576 | if(!isNumero){ |
---|
| 577 | alert(get_lang("Enter a numerical value to the message size!")); |
---|
[3961] | 578 | return false; |
---|
[3837] | 579 | } |
---|
[3830] | 580 | } |
---|
[2] | 581 | for(var i=1; i < 4; i++){mount_rule += LTrim(Element("field"+i).value) + "&&";} |
---|
| 582 | var v_checked = false; |
---|
| 583 | if(Element("radio1").checked){ |
---|
[3961] | 584 | if( /[^\x00-\x80]/.test( Element("select_mailboxes").value ) ) { |
---|
| 585 | alert( get_lang ( 'The selected folder cotain any accented character. The filter dont work with accented folders. Please, rename the folder or choose another folder.' ) ); |
---|
| 586 | return false; |
---|
| 587 | } |
---|
| 588 | |
---|
[2] | 589 | mount_rule += "folder&&"; |
---|
| 590 | var sel_nameBox = Element("select_mailboxes"); |
---|
| 591 | for(var i=0; i < sel_nameBox.options.length; i++){if(sel_nameBox.options[i].selected == true){mount_rule += sel_nameBox.options[i].value + "&&";}} |
---|
| 592 | v_checked = true; |
---|
| 593 | } |
---|
| 594 | if(Element("radio2").checked){ |
---|
[3961] | 595 | if (this.forwardAddressValidation(Element("field5").value)){ |
---|
| 596 | mount_rule += "address&&"; |
---|
| 597 | if(Element("field5").value == ""){ |
---|
| 598 | alert(get_lang("Inform a forwarding e-mail!")); |
---|
| 599 | return false; |
---|
| 600 | }else{ |
---|
| 601 | if(validateEmail(Element("field5").value)){ |
---|
[2] | 602 | mount_rule += Element("field5").value + "&&"; |
---|
| 603 | }else{ |
---|
[53] | 604 | alert(get_lang("Inform a valid e-mail!")); |
---|
[2] | 605 | return false; |
---|
| 606 | } |
---|
| 607 | } |
---|
| 608 | v_checked = true; |
---|
[3407] | 609 | } |
---|
| 610 | else |
---|
| 611 | { |
---|
| 612 | alert(get_lang("You can't forward e-mails to this domain: %1", Element("field5").value.split("@")[1])); |
---|
| 613 | return false; |
---|
| 614 | } |
---|
[2] | 615 | } |
---|
| 616 | if(Element("radio3").checked){ |
---|
| 617 | mount_rule += "reject&&"; |
---|
| 618 | if(Element("field6").value == ""){ |
---|
[53] | 619 | alert(get_lang("Inform a text for rejection!")); |
---|
[2] | 620 | return false; |
---|
| 621 | }else{ |
---|
| 622 | mount_rule += Element("field6").value + "&&"; |
---|
| 623 | } |
---|
| 624 | v_checked = true; |
---|
| 625 | } |
---|
| 626 | if(Element("radio4").checked){ |
---|
| 627 | mount_rule += "discard&&&&"; |
---|
| 628 | v_checked = true; |
---|
| 629 | } |
---|
[3441] | 630 | if(Element("radio5").checked){ |
---|
| 631 | mount_rule += "flagged&&&&"; |
---|
| 632 | v_checked = true; |
---|
| 633 | } |
---|
[2] | 634 | if(!v_checked){ |
---|
[53] | 635 | alert(get_lang("No option marked!")); |
---|
[2] | 636 | return false; |
---|
| 637 | } |
---|
| 638 | var opts = ""; |
---|
[3438] | 639 | if(Element("checkBox2").checked == true){ |
---|
| 640 | opts += ",checkBox2"; |
---|
| 641 | } |
---|
| 642 | if(Element("select_size").options[1].selected == true){ |
---|
| 643 | opts += ",select_size=1"; |
---|
| 644 | } |
---|
| 645 | if(Element("select_rules").options[1].selected == true){ |
---|
| 646 | opts += ",select_rules=1"; |
---|
| 647 | } |
---|
| 648 | for(var i=0; i < this.values.length; i++){ |
---|
| 649 | if(this.values[i] == opts){ |
---|
| 650 | mount_rule += i + "&&"; |
---|
| 651 | } |
---|
| 652 | } |
---|
[2] | 653 | mount_rule += "&&&&"; |
---|
[3438] | 654 | if(LTrim(Element("field4").value) != "" && LTrim(Element("field4").value) >= 0){ |
---|
[2] | 655 | mount_rule += LTrim(Element("field4").value); |
---|
| 656 | } |
---|
| 657 | if(form[0] == "new") |
---|
[564] | 658 | { |
---|
[2] | 659 | this.rulest[this.rulest.length] = mount_rule; |
---|
[564] | 660 | } |
---|
[2] | 661 | else |
---|
| 662 | this.rulest[this.ind] = mount_rule; |
---|
[564] | 663 | } |
---|
| 664 | else if(form[1] == "out") |
---|
| 665 | { |
---|
[2] | 666 | mount_rule = ""; |
---|
[197] | 667 | var fld_emails = this.email_ld; // Get first email of list! |
---|
[2] | 668 | var fld_men = Element("field8"); |
---|
| 669 | mount_rule = "#vacation&&"; |
---|
[197] | 670 | mount_rule += "1&&"; |
---|
| 671 | mount_rule += "\"" + fld_emails + "\", "; |
---|
| 672 | mount_rule = mount_rule.substr(0,(mount_rule.length - 2)); |
---|
| 673 | mount_rule += "&&"; |
---|
| 674 | mount_rule += fld_men.value + "&&on"; |
---|
[2] | 675 | if(LTrim(fld_men.value) == ""){ |
---|
[3833] | 676 | alert(get_lang("Message required")); |
---|
[2] | 677 | return false; |
---|
| 678 | } |
---|
[197] | 679 | this.out_officeR = mount_rule; |
---|
[2] | 680 | } |
---|
[564] | 681 | else if(form[1] == "voip") |
---|
| 682 | { |
---|
| 683 | if( Element("field9").value != "" && LTrim(Element("field9").value) != "" ) |
---|
| 684 | { |
---|
| 685 | mount_rule = "#rule&&"; |
---|
| 686 | if(form[0] == "new") |
---|
| 687 | { |
---|
| 688 | n_rule = "1&&"; |
---|
| 689 | if( this.rulesVoip.length > 0 ) |
---|
| 690 | { |
---|
| 691 | aux = this.rulesVoip[this.rulesVoip.length - parseInt(1)].split("&&"); |
---|
| 692 | n_rule = (parseInt(aux[1]) + parseInt(2)) + "&&"; |
---|
| 693 | } |
---|
| 694 | mount_rule += n_rule + "ENABLED&&"; |
---|
| 695 | } |
---|
| 696 | else |
---|
| 697 | { |
---|
| 698 | n_rule = this.rulesVoip[this.ind].split("&&"); |
---|
| 699 | mount_rule += n_rule[1] + "&&"; |
---|
| 700 | mount_rule += n_rule[2] + "&&"; |
---|
| 701 | } |
---|
| 702 | |
---|
| 703 | if ( Element("field9").value.indexOf("#") >= 0 ) |
---|
| 704 | { |
---|
| 705 | alert(get_lang('Caracter "#" is not allowed!')); |
---|
| 706 | return false; |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | mount_rule = mount_rule + "&&&&" + Element("field9").value + "&¬ify&&" + preferences.voip_email_redirect + "&&8&&&&&&0"; |
---|
| 710 | |
---|
| 711 | if( form[0] == "new" ) |
---|
| 712 | { |
---|
| 713 | this.rulesVoip[this.rulesVoip.length] = mount_rule; |
---|
| 714 | } |
---|
| 715 | else |
---|
| 716 | { |
---|
| 717 | this.rulesVoip[this.ind] = mount_rule; |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | else |
---|
| 721 | { |
---|
| 722 | alert( 'CAMPOS EM BRANCO !!' ); |
---|
| 723 | return false; |
---|
| 724 | } |
---|
| 725 | } |
---|
| 726 | |
---|
[2] | 727 | Element('form_buttons').style.display = ''; |
---|
| 728 | this.reload_rules(); |
---|
| 729 | } |
---|
| 730 | |
---|
[564] | 731 | cfilter.prototype.close_frm= function() |
---|
| 732 | { |
---|
[2] | 733 | filters.filter_Sh['window_ffilter_ccform'].close(); |
---|
| 734 | } |
---|
| 735 | |
---|
[564] | 736 | cfilter.prototype.saved_all = function() |
---|
| 737 | { |
---|
[2] | 738 | var aux_rul = ""; |
---|
| 739 | var _this = this; |
---|
[564] | 740 | var cont = 0; |
---|
| 741 | |
---|
| 742 | // Regras Gerais |
---|
| 743 | if(_this.rulest.length > 0) |
---|
| 744 | { |
---|
| 745 | for(var i=0; i < _this.rulest.length; i++) |
---|
| 746 | { |
---|
| 747 | var fieldsNormal = _this.rulest[i].split("&&"); |
---|
[2] | 748 | aux_rul += "_begin_##"; |
---|
[564] | 749 | for(var j=0 ; j < fieldsNormal.length; j++) |
---|
| 750 | { |
---|
| 751 | aux_rul += url_encode(fieldsNormal[j]) + "##"; |
---|
| 752 | cont = parseInt(fieldsNormal[1]); |
---|
[2] | 753 | } |
---|
| 754 | aux_rul += "_end_\n"; |
---|
| 755 | } |
---|
| 756 | } |
---|
[564] | 757 | |
---|
| 758 | // Voip |
---|
| 759 | if(_this.rulesVoip.length > 0) |
---|
| 760 | { |
---|
| 761 | for(var i=0; i < _this.rulesVoip.length; i++) |
---|
| 762 | { |
---|
| 763 | var fieldsVoip = _this.rulesVoip[i].split("&&"); |
---|
| 764 | aux_rul += "_begin_##"; |
---|
| 765 | for(var j=0 ; j < fieldsVoip.length; j++) |
---|
| 766 | { |
---|
| 767 | if(j == 1) |
---|
| 768 | { |
---|
| 769 | if( cont == 0 ) |
---|
| 770 | cont = parseInt(1); |
---|
| 771 | else |
---|
| 772 | cont = parseInt(cont) + parseInt(2); |
---|
| 773 | aux_rul += cont; |
---|
| 774 | aux_rul += "##"; |
---|
| 775 | } |
---|
| 776 | else |
---|
| 777 | aux_rul += url_encode(fieldsVoip[j]) + "##"; |
---|
| 778 | } |
---|
| 779 | aux_rul += "_end_\n"; |
---|
| 780 | } |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | // Fora do Escritório |
---|
| 784 | if(_this.out_officeR.length > 0) |
---|
| 785 | { |
---|
[197] | 786 | var aux = _this.out_officeR.split("&&"); |
---|
[2] | 787 | aux_rul += "_begin_##"; |
---|
[564] | 788 | for(var j=0 ; j < aux.length; j++) |
---|
| 789 | { |
---|
| 790 | aux_rul += url_encode(aux[j]) + "##"; |
---|
[2] | 791 | } |
---|
| 792 | aux_rul += "_end_\n"; |
---|
[564] | 793 | _this.out_officeF = (aux[4].replace("\n","") === "off") ? false : true; |
---|
[206] | 794 | //Save outoffice in prefs: |
---|
[271] | 795 | connector.loadScript("preferences"); |
---|
[3815] | 796 | if(typeof(prefe) == 'undefined') |
---|
| 797 | setTimeout("filter.saved_all();",500); |
---|
| 798 | else |
---|
| 799 | prefe.save("outoffice", _this.out_officeF); |
---|
[2] | 800 | } |
---|
[564] | 801 | |
---|
| 802 | var h_filter = function(data) |
---|
| 803 | { |
---|
[3438] | 804 | if(data != "Ok"){alert("Erro : \n" + get_lang(data));} |
---|
[2] | 805 | } |
---|
| 806 | var args = "$this.ScriptS.rec_rules"; |
---|
| 807 | var params = "arfilter="+aux_rul; |
---|
[3018] | 808 | if(!_this.criticalError) |
---|
| 809 | cExecute(args,h_filter,params); |
---|
[2] | 810 | } |
---|
| 811 | |
---|
| 812 | // build object |
---|
| 813 | var filter; |
---|
[689] | 814 | filter = new cfilter(); |
---|