tbrehm
2008-07-13 eea5cff24c965684882e88632095d725e2d14637
The user email filters were now written to the custom mail rules field.
6 files modified
107 ■■■■■ changed files
interface/lib/classes/db_mysql.inc.php 2 ●●● patch | view | raw | blame | history
interface/web/mail/form/mail_user_filter.tform.php 4 ●●●● patch | view | raw | blame | history
interface/web/mail/lib/lang/en_mail_user_filter.lng 1 ●●●● patch | view | raw | blame | history
interface/web/mail/list/mail_user_filter.list.php 2 ●●● patch | view | raw | blame | history
interface/web/mail/mail_user_filter_edit.php 92 ●●●●● patch | view | raw | blame | history
interface/web/mail/templates/mail_user_custom_rules_edit.htm 6 ●●●● patch | view | raw | blame | history
interface/lib/classes/db_mysql.inc.php
@@ -278,7 +278,7 @@
        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;
        
interface/web/mail/form/mail_user_filter.tform.php
@@ -39,7 +39,7 @@
$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 @@
            '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',
interface/web/mail/lib/lang/en_mail_user_filter.lng
@@ -7,4 +7,5 @@
$wb["btn_cancel_txt"] = 'Cancel';
$wb["rulename_error_empty"] = 'Name is empty.';
$wb["searchterm_is_empty"] = 'Search term is empty.';
$wb["source_txt"] = 'Source';
?>
interface/web/mail/list/mail_user_filter.list.php
@@ -28,7 +28,7 @@
$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";
interface/web/mail/mail_user_filter_edit.php
@@ -53,17 +53,105 @@
    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;
interface/web/mail/templates/mail_user_custom_rules_edit.htm
@@ -1,7 +1,7 @@
<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'}">