Skip to content

Commit eea5cff

Browse files
committed
The user email filters were now written to the custom mail rules field.
1 parent 3c5c2dc commit eea5cff

File tree

6 files changed

+98
-9
lines changed

6 files changed

+98
-9
lines changed

interface/lib/classes/db_mysql.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function datalogSave($db_table, $action, $primary_field, $primary_id, $re
278278
return true;
279279
}
280280

281-
//** Updates a record and saves the changes into the datalog
281+
//** Inserts a record and saves the changes into the datalog
282282
public function datalogInsert($tablename, $insert_data, $index_field) {
283283
global $app;
284284

interface/web/mail/form/mail_user_filter.tform.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
$form["action"] = "mail_user_filter_edit.php";
4040
$form["db_table"] = "mail_user_filter";
4141
$form["db_table_idx"] = "filter_id";
42-
$form["db_history"] = "yes";
42+
$form["db_history"] = "no";
4343
$form["tab_default"] = "filter";
4444
$form["list_default"] = "mail_user_filter_list.php";
4545
$form["auth"] = 'yes'; // yes / no
@@ -81,7 +81,7 @@
8181
'datatype' => 'VARCHAR',
8282
'formtype' => 'SELECT',
8383
'default' => '',
84-
'value' => array('Subject' => 'Subject','From'=>'From','To'=>'To','Header'=>'Custom Header')
84+
'value' => array('Subject' => 'Subject','From'=>'From','To'=>'To')
8585
),
8686
'op' => array (
8787
'datatype' => 'VARCHAR',

interface/web/mail/lib/lang/en_mail_user_filter.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ $wb["btn_save_txt"] = 'Save';
77
$wb["btn_cancel_txt"] = 'Cancel';
88
$wb["rulename_error_empty"] = 'Name is empty.';
99
$wb["searchterm_is_empty"] = 'Search term is empty.';
10+
$wb["source_txt"] = 'Source';
1011
?>

interface/web/mail/list/mail_user_filter.list.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
$liste["records_per_page"] = 15;
2929

3030
// Script File of the list
31-
$liste["file"] = "mail_user_filter_list.php";
31+
$liste["file"] = "mail_user_list.php";
3232

3333
// Script file of the edit form
3434
$liste["edit_file"] = "mail_user_filter_edit.php";

interface/web/mail/mail_user_filter_edit.php

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,105 @@ class page_action extends tform_actions {
5353
function onSubmit() {
5454
global $app, $conf;
5555

56-
// Get the parent soa record of the domain
56+
// Get the parent mail_user record
5757
$mailuser = $app->db->queryOneRecord("SELECT * FROM mail_user WHERE mailuser_id = '".intval($_REQUEST["mailuser_id"])."' AND ".$app->tform->getAuthSQL('r'));
58+
5859
// Check if Domain belongs to user
5960
if($mailuser["mailuser_id"] != $_POST["mailuser_id"]) $app->tform->errorMessage .= $app->tform->wordbook["no_mailuser_perm"];
6061

61-
// Set the server ID of the rr record to the same server ID as the parent record.
62+
// Set the mailuser_id
6263
$this->dataRecord["mailuser_id"] = $mailuser["mailuser_id"];
6364

6465
parent::onSubmit();
6566
}
6667

68+
function onAfterInsert() {
69+
global $app, $conf;
70+
71+
$mailuser = $app->db->queryOneRecord("SELECT custom_mailfilter FROM mail_user WHERE mailuser_id = ".$this->dataRecord["mailuser_id"]);
72+
$rule_content = $mailuser['custom_mailfilter']."\n".$app->db->quote($this->getRule());
73+
$app->db->datalogUpdate('mail_user', "custom_mailfilter = '$rule_content'", 'mailuser_id', $this->dataRecord["mailuser_id"]);
74+
75+
}
76+
77+
function onAfterUpdate() {
78+
global $app, $conf;
79+
80+
$mailuser = $app->db->queryOneRecord("SELECT custom_mailfilter FROM mail_user WHERE mailuser_id = ".$this->dataRecord["mailuser_id"]);
81+
$skip = false;
82+
$lines = explode("\n",$mailuser['custom_mailfilter']);
83+
$out = '';
84+
$found = false;
85+
86+
foreach($lines as $line) {
87+
$line = trim($line);
88+
if($line == '### BEGIN FILTER_ID:'.$this->id) {
89+
$skip = true;
90+
$found = true;
91+
}
92+
if($skip == false && $line != '') $out .= $line ."\n";
93+
if($line == '### END FILTER_ID:'.$this->id) {
94+
$out .= $this->getRule();
95+
$skip = false;
96+
}
97+
}
98+
99+
// We did not found our rule, so we add it now.
100+
if($found == false) {
101+
$out .= $this->getRule();
102+
}
103+
104+
$out = addslashes($out);
105+
$app->db->datalogUpdate('mail_user', "custom_mailfilter = '$out'", 'mailuser_id', $this->dataRecord["mailuser_id"]);
106+
107+
}
108+
109+
function getRule() {
110+
111+
$content = '';
112+
$content .= '### BEGIN FILTER_ID:'.$this->id."\n";
113+
114+
if($this->dataRecord["action"] == 'move') {
115+
116+
$content .= "
117+
`test -e ".'$DEFAULT/'.$this->dataRecord["target"]."`
118+
if ( ".'$RETURNCODE'." != 0 )
119+
{
120+
`maildirmake -f ".$this->dataRecord["target"].' $DEFAULT'."`
121+
`chmod -R 0700 ".'$DEFAULT/'.$this->dataRecord["target"]."`
122+
}
123+
";
124+
}
125+
126+
$content .= "if (/^".$this->dataRecord["source"].":";
127+
128+
if($this->dataRecord["op"] == 'contains') {
129+
$content .= ".*".$this->dataRecord["searchterm"]."/:h)\n";
130+
} elseif ($this->dataRecord["op"] == 'is') {
131+
$content .= $this->dataRecord["searchterm"]."$/:h)\n";
132+
} elseif ($this->dataRecord["op"] == 'begins') {
133+
$content .= $this->dataRecord["searchterm"]."/:h)\n";
134+
} elseif ($this->dataRecord["op"] == 'ends') {
135+
$content .= ".*".$this->dataRecord["searchterm"]."$/:h)\n";
136+
}
137+
138+
$content .= "{\n";
139+
$content .= "exception {\n";
140+
141+
if($this->dataRecord["action"] == 'move') {
142+
$content .= 'to $DEFAULT/'.$this->dataRecord["target"]."/\n";
143+
} else {
144+
$content .= "to /dev/null\n";
145+
}
146+
147+
$content .= "}\n";
148+
$content .= "}\n";
149+
150+
$content .= '### END FILTER_ID:'.$this->id."\n";
151+
152+
return $content;
153+
}
154+
67155
}
68156

69157
$page = new page_action;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<table width="500" border="0" cellspacing="0" cellpadding="2">
22
<tr>
33
<td class="frmText11">{tmpl_var name='custom_mailfilter_txt'}:</td>
4-
<td class="frmText11"><textarea name='custom_mailfilter' cols='30' rows='15'>{tmpl_var name='custom_mailfilter'}</textarea></td>
4+
<td class="frmText11"><textarea name='custom_mailfilter' cols='50' rows='15'>{tmpl_var name='custom_mailfilter'}</textarea></td>
55
</tr> <tr>
66
<td class="frmText11">&nbsp;</td>
77
<td class="frmText11">&nbsp;</td>
@@ -11,6 +11,6 @@
1111
<td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','mail/mail_user_edit.php');"><div class="buttonEnding"></div>&nbsp;
1212
<input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('mail/mail_user_list.php');"><div class="buttonEnding"></div>
1313
</td>
14-
</tr>
15-
</table>
14+
</tr>
15+
</table>
1616
<input type="hidden" name="id" value="{tmpl_var name='id'}">

0 commit comments

Comments
 (0)