source: branches/2.2/expressoMail1_2/js/filter.js @ 4541

Revision 4541, 26.6 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1927 - Correcao para regras modificadas quando migra o expresso 2.0 para o 2.2

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