| 1 | <?php |
| 2 | /******************************************************************************** |
| 3 | * include/plugin_header.inc.php : The class for Header Based Match |
| 4 | * ----------------------------- |
| 5 | * |
| 6 | * This file is part of the philter distribution |
| 7 | * Copyright: See COPYING files that comes with this distribution |
| 8 | ********************************************************************************/ |
| 9 | |
| 10 | class HdrPlugin extends MatchPlugin { |
| 11 | function HdrPlugin($glob) { $this->MatchPlugin(false); } |
| 12 | function rtti() { return 2; } |
| 13 | function name() { return _i18n('2_hdr'); } |
| 14 | |
| 15 | function to_js() { |
| 16 | $_2_dests = _i18n('2_dests'); |
| 17 | $_2_contains = _i18n('2_contains'); |
| 18 | $_2_not_contains = _i18n('2_not_contains'); |
| 19 | return <<<EOF |
| 20 | function(Node, data) { |
| 21 | var i,j; |
| 22 | var sel = 0; |
| 23 | |
| 24 | Node.appendChild(document.createTextNode(' ')); |
| 25 | |
| 26 | var hdr_s = document.createElement('select'); |
| 27 | hdr_s.setAttribute('name', Node.name+'[1]'); |
| 28 | Node.appendChild(hdr_s); |
| 29 | |
| 30 | hdr_s.options[0] = new Option('<$_2_dests>',0,false,data[1]==0); |
| 31 | hdr_s.options[1] = new Option('Subject:',1,false,data[1]==1); |
| 32 | hdr_s.options[2] = new Option('From:',2,false,data[1]==2); |
| 33 | hdr_s.options[3] = new Option('To:',3,false,data[1]==3); |
| 34 | hdr_s.options[4] = new Option('Cc:',4,false,data[1]==4); |
| 35 | hdr_s.options[5] = new Option('Reply-To:',5,false,data[1]==5); |
| 36 | hdr_s.options[6] = new Option('Organization:',6,false,data[1]==6); |
| 37 | hdr_s.options[7] = new Option('List-Id:',7,false,data[1]==7); |
| 38 | hdr_s.options[8] = new Option('X-Mailing-List:',8,false,data[1]==8); |
| 39 | hdr_s.selectIndex = data[1]; |
| 40 | |
| 41 | Node.appendChild(document.createTextNode(' ')); |
| 42 | var op_s = document.createElement('select'); |
| 43 | op_s.setAttribute('name', Node.name+'[2]'); |
| 44 | Node.appendChild(op_s); |
| 45 | |
| 46 | op_s.options[0] = new Option('$_2_contains',0,false,data[2]==0); |
| 47 | op_s.options[1] = new Option('$_2_not_contains',1,false,data[2]==1); |
| 48 | op_s.options[2] = new Option(' = ',2,false,data[2]==2); |
| 49 | op_s.options[3] = new Option(' != ',3,false,data[2]==3); |
| 50 | op_s.selectIndex = data[2]; |
| 51 | |
| 52 | Node.appendChild(document.createTextNode(' ')); |
| 53 | var txt_i = document.createElement('input'); |
| 54 | txt_i.setAttribute('type','text'); |
| 55 | txt_i.setAttribute('name', Node.name+'[3]'); |
| 56 | txt_i.setAttribute('value', (data[3] ? data[3] : '') ); |
| 57 | Node.appendChild(txt_i); |
| 58 | } |
| 59 | EOF; |
| 60 | } |
| 61 | |
| 62 | function to_string($_data) { |
| 63 | switch($_data[1]) { |
| 64 | case 0: $res = '^TO'; break; |
| 65 | case 1: $res = '^Subject:'; break; |
| 66 | case 2: $res = '^From:'; break; |
| 67 | case 3: $res = '^To:'; break; |
| 68 | case 4: $res = '^Cc:'; break; |
| 69 | case 5: $res = '^Reply-To:'; break; |
| 70 | case 6: $res = '^Organization:'; break; |
| 71 | case 7: $res = '^List-Id:'; break; |
| 72 | case 8: $res = '^X-Mailing-List:'; break; |
| 73 | } |
| 74 | switch($_data[2]) { |
| 75 | case 0: $res = "* $res.*{$_data[3]}\n"; break; |
| 76 | case 1: $res = "* !$res.*{$_data[3]}\n"; break; |
| 77 | case 2: $res = "* $res {$_data[3]}$\n"; break; |
| 78 | case 3: $res = "* !$res {$_data[3]}$\n"; break; |
| 79 | } |
| 80 | return $res; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /******************************************************************************** |
| 85 | * $Id$ |
| 86 | * vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 textwidth=100: |
| 87 | ********************************************************************************/ |
| 88 | ?> |