Commit eea5cff2 authored by tbrehm's avatar tbrehm
Browse files

The user email filters were now written to the custom mail rules field.

parent 3c5c2dc6
......@@ -278,7 +278,7 @@ class db
return true;
}
//** Updates a record and saves the changes into the datalog
//** Inserts a record and saves the changes into the datalog
public function datalogInsert($tablename, $insert_data, $index_field) {
global $app;
......
......@@ -39,7 +39,7 @@ $form["name"] = "mail_user_filter";
$form["action"] = "mail_user_filter_edit.php";
$form["db_table"] = "mail_user_filter";
$form["db_table_idx"] = "filter_id";
$form["db_history"] = "yes";
$form["db_history"] = "no";
$form["tab_default"] = "filter";
$form["list_default"] = "mail_user_filter_list.php";
$form["auth"] = 'yes'; // yes / no
......@@ -81,7 +81,7 @@ $form["tabs"]['filter'] = array (
'datatype' => 'VARCHAR',
'formtype' => 'SELECT',
'default' => '',
'value' => array('Subject' => 'Subject','From'=>'From','To'=>'To','Header'=>'Custom Header')
'value' => array('Subject' => 'Subject','From'=>'From','To'=>'To')
),
'op' => array (
'datatype' => 'VARCHAR',
......
......@@ -7,4 +7,5 @@ $wb["btn_save_txt"] = 'Save';
$wb["btn_cancel_txt"] = 'Cancel';
$wb["rulename_error_empty"] = 'Name is empty.';
$wb["searchterm_is_empty"] = 'Search term is empty.';
$wb["source_txt"] = 'Source';
?>
\ No newline at end of file
......@@ -28,7 +28,7 @@ $liste["search_prefix"] = "search_";
$liste["records_per_page"] = 15;
// Script File of the list
$liste["file"] = "mail_user_filter_list.php";
$liste["file"] = "mail_user_list.php";
// Script file of the edit form
$liste["edit_file"] = "mail_user_filter_edit.php";
......
......@@ -53,17 +53,105 @@ class page_action extends tform_actions {
function onSubmit() {
global $app, $conf;
// Get the parent soa record of the domain
// Get the parent mail_user record
$mailuser = $app->db->queryOneRecord("SELECT * FROM mail_user WHERE mailuser_id = '".intval($_REQUEST["mailuser_id"])."' AND ".$app->tform->getAuthSQL('r'));
// Check if Domain belongs to user
if($mailuser["mailuser_id"] != $_POST["mailuser_id"]) $app->tform->errorMessage .= $app->tform->wordbook["no_mailuser_perm"];
// Set the server ID of the rr record to the same server ID as the parent record.
// Set the mailuser_id
$this->dataRecord["mailuser_id"] = $mailuser["mailuser_id"];
parent::onSubmit();
}
function onAfterInsert() {
global $app, $conf;
$mailuser = $app->db->queryOneRecord("SELECT custom_mailfilter FROM mail_user WHERE mailuser_id = ".$this->dataRecord["mailuser_id"]);
$rule_content = $mailuser['custom_mailfilter']."\n".$app->db->quote($this->getRule());
$app->db->datalogUpdate('mail_user', "custom_mailfilter = '$rule_content'", 'mailuser_id', $this->dataRecord["mailuser_id"]);
}
function onAfterUpdate() {
global $app, $conf;
$mailuser = $app->db->queryOneRecord("SELECT custom_mailfilter FROM mail_user WHERE mailuser_id = ".$this->dataRecord["mailuser_id"]);
$skip = false;
$lines = explode("\n",$mailuser['custom_mailfilter']);
$out = '';
$found = false;
foreach($lines as $line) {
$line = trim($line);
if($line == '### BEGIN FILTER_ID:'.$this->id) {
$skip = true;
$found = true;
}
if($skip == false && $line != '') $out .= $line ."\n";
if($line == '### END FILTER_ID:'.$this->id) {
$out .= $this->getRule();
$skip = false;
}
}
// We did not found our rule, so we add it now.
if($found == false) {
$out .= $this->getRule();
}
$out = addslashes($out);
$app->db->datalogUpdate('mail_user', "custom_mailfilter = '$out'", 'mailuser_id', $this->dataRecord["mailuser_id"]);
}
function getRule() {
$content = '';
$content .= '### BEGIN FILTER_ID:'.$this->id."\n";
if($this->dataRecord["action"] == 'move') {
$content .= "
`test -e ".'$DEFAULT/'.$this->dataRecord["target"]."`
if ( ".'$RETURNCODE'." != 0 )
{
`maildirmake -f ".$this->dataRecord["target"].' $DEFAULT'."`
`chmod -R 0700 ".'$DEFAULT/'.$this->dataRecord["target"]."`
}
";
}
$content .= "if (/^".$this->dataRecord["source"].":";
if($this->dataRecord["op"] == 'contains') {
$content .= ".*".$this->dataRecord["searchterm"]."/:h)\n";
} elseif ($this->dataRecord["op"] == 'is') {
$content .= $this->dataRecord["searchterm"]."$/:h)\n";
} elseif ($this->dataRecord["op"] == 'begins') {
$content .= $this->dataRecord["searchterm"]."/:h)\n";
} elseif ($this->dataRecord["op"] == 'ends') {
$content .= ".*".$this->dataRecord["searchterm"]."$/:h)\n";
}
$content .= "{\n";
$content .= "exception {\n";
if($this->dataRecord["action"] == 'move') {
$content .= 'to $DEFAULT/'.$this->dataRecord["target"]."/\n";
} else {
$content .= "to /dev/null\n";
}
$content .= "}\n";
$content .= "}\n";
$content .= '### END FILTER_ID:'.$this->id."\n";
return $content;
}
}
$page = new page_action;
......
<table width="500" border="0" cellspacing="0" cellpadding="2">
<tr>
<td class="frmText11">{tmpl_var name='custom_mailfilter_txt'}:</td>
<td class="frmText11"><textarea name='custom_mailfilter' cols='30' rows='15'>{tmpl_var name='custom_mailfilter'}</textarea></td>
<td class="frmText11"><textarea name='custom_mailfilter' cols='50' rows='15'>{tmpl_var name='custom_mailfilter'}</textarea></td>
</tr> <tr>
<td class="frmText11">&nbsp;</td>
<td class="frmText11">&nbsp;</td>
......@@ -11,6 +11,6 @@
<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;
<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>
</td>
</tr>
</table>
</tr>
</table>
<input type="hidden" name="id" value="{tmpl_var name='id'}">
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment