forked from poppyred/1.6.x
/
procmail.functions.php
executable file
·163 lines (139 loc) · 5.93 KB
/
procmail.functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
include_once('ressources/class.procmail.inc');
include_once('ressources/class.templates.inc');
include_once('ressources/class.ini.inc');
if(isset($_GET["TreeProcMailRules"])){TreeProcMailRules();exit;}
if(isset($_GET["ProcmailAddRule"])){ProcmailAddRule();exit;}
if(isset($_GET["procmail_edit_rule"])){procmail_edit_rule();exit;}
if(isset($_GET["ProcMailRuleMove"])){ProcMailRuleMove();exit;}
if(isset($_GET["ProcMailRuleDelete"])){ProcMailRuleDelete();exit;}
if(isset($_GET["TreeProcMailApplyConfig"])){TreeProcMailApplyConfig();exit;}
function TreeProcMailRules(){
$usr=new usersMenus();
$tpl=new Templates();
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$html="<fieldset><legend>{procmail_rules}</legend>
<table>
<tr>
<td><input type='button' value='« {add_new_rule} »' OnClick=\"javascript:ProcmailAddRule('-1');\"></td>
</tr>
</table>
<br>" . table_rules() . "
</fieldset>";
echo DIV_SHADOW($tpl->_ENGINE_parse_body($html),'windows');
}
function table_rules($noform=0){
$usr=new usersMenus();
$tpl=new Templates();
$Sender=0;
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$proc=new procmail();
if(is_array($proc->array_rule)){
while (list ($num, $ligne) = each ($proc->array_rule) ){
if($noform==0){
$cell_up="<td width=1%>" . imgtootltip('arrow_up.gif','{up}',"ProcMailRuleMove($num,'up',$Sender)") ."</td>";
$cell_down="<td width=1%>" . imgtootltip('arrow_down.gif','{down}',"ProcMailRuleMove($num,'down',$Sender)") ."</td>";
$cell_del="<td width=1%>" . imgtootltip('ed_delete.gif','{delete}',"ProcMailRuleDelete($num,$Sender)") ."</td>";
$move="<table style='width:20px'><tr>$cell_up$cell_down$cell_del</tr></table>";
}
}
$html=$html . "
<table align='center' style='margin:3px;border:1px dotted #CCCCCC;width:90%'>
<tr>
<td width=1%><img src='img/alias-18.gif'></td>
<td width=90%><strong><a href=\"javascript:ProcmailAddRule('$num');\">{$ligne["name"]}:</strong></a></td>
<td>$move</td>
</tr>
<tr>
<td> </td>
<td style='padding-left:5px' colspan=2><i>{if} <strong>{$ligne["header_name"]}</strong> {$proc->condition_array[$ligne["condition"]]} <strong>{$ligne["string"]}</strong> {then} {$proc->action_array[$ligne["action"]]}</i></td>
</tr>
</table>";
}
return $tpl->_ENGINE_parse_body("<div id='rules'>$html</div>");
}
function procmail_edit_rule(){
$rule_id=$_GET["procmail_edit_rule"];
$tpl=new templates();
unset($_GET["procmail_edit_rule"]);
if($_GET["name"]==null){echo $tpl->_ENGINE_parse_body('{form_error} ->{rule_name}');exit; }
if($_GET["string"]==null){echo $tpl->_ENGINE_parse_body('{form_error} ->{pattern}');exit; }
$proc=new procmail();
if($rule_id==-1){
$proc->array_rule[]=$_GET;
}else{$proc->array_rule[$rule_id]=$_GET;}
if($proc->save_rules()){echo $tpl->_ENGINE_parse_body('{success}');}
}
function ProcmailAddRule(){
$usr=new usersMenus();
$tpl=new Templates();
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$proc=new procmail();
$proc->header_database[null]='{select}';
$if=Field_array_Hash($proc->condition_array,'condition',null);
$rule_id=$_GET["ProcmailAddRule"];
$proc=new procmail();
$hash=$proc->array_rule[$rule_id];
if($_GET["ProcmailAddRule"]==-1){$title='{add_rule}';}else{$title="{edit_rule} {$_GET["ProcmailAddRule"]}";
$subtitle="<div style='font-size:12px;border-bottom:1px solid #005447;width:100%;font-wieght:bolder;color:#005447;margin-bottom:5px;'><strong>{$hash["name"]}</strong></div>";
}
$header_name=Field_array_Hash($proc->header_database,'header_name',$hash["header_name"]);
$html="<fieldset><legend>$title</legend>
<form name='proc_rule'>
<input type='hidden' name='procmail_edit_rule' value='{$_GET["ProcmailAddRule"]}'>
<table>
<tr>
<td><input type='button' value='« {manage_procmail_rules} »' OnClick=\"javascript:TreeProcMailRules();\"></td>
</tr>
</table><br>
$subtitle
<table style='margin:3px;border:1px solid #CCCCCC;padding:5px;width:99%'>
<tr>
</tr>
<tr><td colspan=3><strong>{rule_name}</strong>:" . Field_text('name',$hash["name"],'width:70%') . "</td>
</tr>
<td><strong>{if_in}</strong></td>
<td>$header_name</td>
<td>$if</td>
</tr>
<tr><td colspan=3><strong>{pattern}</strong>:" . Field_text('string',$hash["string"],'width:80%') . "<br><code>*,? {supported}</code></td>
</tr>
<tr>
<td><strong>{then}:</strong></td>
<td colspan=2>" . Field_array_Hash($proc->action_array,"action",$hash["action"]) . "</td>
</table>
</form>
<div style='padding-right:10px;text-align:right' align='right'><input type='button' value='{submit} »' OnClick=\"javascript:ParseForm('proc_rule','procmail.functions.php',true);\"></div>
</fieldset>";
echo DIV_SHADOW($tpl->_ENGINE_parse_body($html),'windows');
}
function ProcMailRuleMove(){
$usr=new usersMenus();
$tpl=new Templates();
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$proc=new procmail();
if($_GET["direction"]=='up'){
$proc->array_rule=array_move_element($proc->array_rule,$proc->array_rule[$_GET["ProcMailRuleMove"]],'up');
}else{
$proc->array_rule=array_move_element($proc->array_rule,$proc->array_rule[$_GET["ProcMailRuleMove"]],'down');
}
$proc->save_rules();
echo table_rules();
}
function ProcMailRuleDelete(){
$usr=new usersMenus();
$tpl=new Templates();
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$proc=new procmail();
unset($proc->array_rule[$_GET["ProcMailRuleDelete"]]);
$proc->save_rules();
echo table_rules();
}
function TreeProcMailApplyConfig(){
$usr=new usersMenus();
$tpl=new Templates();
if($usr->AsMailBoxAdministrator==false){echo $tpl->_ENGINE_parse_body('{no_privileges}');exit;}
$proc=new procmail();
$proc->SaveItToDisk();
echo $tpl->_ENGINE_parse_body('{success}');exit;}
?>