From e28564dbde4f922a6a8263e3dea32d56b60b5b5b Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 16 Jun 2010 11:41:46 -0400
Subject: [PATCH] Implemented: FS#468 - Client name conversion in FTP user too restricted

---
 server/plugins-available/maildrop_plugin.inc.php |   56 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/server/plugins-available/maildrop_plugin.inc.php b/server/plugins-available/maildrop_plugin.inc.php
index 9216b1f..58cbaa4 100644
--- a/server/plugins-available/maildrop_plugin.inc.php
+++ b/server/plugins-available/maildrop_plugin.inc.php
@@ -36,6 +36,19 @@
 	
 	var $mailfilter_config_dir = '';
 	
+	//* This function is called during ispconfig installation to determine
+	//  if a symlink shall be created for this plugin.
+	function onInstall() {
+		global $conf;
+		
+		if($conf['services']['mail'] == true && isset($conf['courier']['installed']) && $conf['courier']['installed'] == true) {
+			return true;
+		} else {
+			return false;
+		}
+		
+	}
+	
 	/*
 	 	This function is called when the plugin is loaded
 	*/
@@ -91,11 +104,12 @@
 			exec("chmod 770 ".$this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0]);
 		}
 		
-		
 		// Check if something has been changed regarding the autoresponders
 		if($data["old"]["autoresponder_text"] != $data["new"]["autoresponder_text"] 
 			    or $data["old"]["autoresponder"] != $data["new"]["autoresponder"]
-			    or (isset($data["new"]["email"]) and $data["old"]["email"] != $data["new"]["email"])) {
+			    or (isset($data["new"]["email"]) and $data["old"]["email"] != $data["new"]["email"])
+			    or $data["old"]["autoresponder_start_date"] != $data["new"]["autoresponder_start_date"]
+			    or $data["old"]["autoresponder_end_date"] != $data["new"]["autoresponder_end_date"]) {
 			   		
 			// We delete the old autoresponder, if it exists
 			$email_parts = explode("@",$data["old"]["email"]);
@@ -103,11 +117,16 @@
 			if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
 			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst';
 			if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
+			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst.gdbm';
+			if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
+			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst.lock';
+			if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
 			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.msg';
 			if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
 			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.autoresponder';
-			if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
-			   		
+			if(is_file($file)) unlink($ar_file) or $app->log("Unable to delete file: $ar_file",LOGLEVEL_WARN);
+			
+			
 			//Now we create the new autoresponder, if it is enabled
 			if($data["new"]["autoresponder"] == 'y') {
 				if(isset($data["new"]["email"])) {
@@ -119,6 +138,15 @@
 				// Load the master template
 				$tpl = file_get_contents($conf["rootpath"].'/conf/autoresponder.master');
 				$tpl = str_replace('{vmail_mailbox_base}',$mail_config["homedir_path"],$tpl);
+				
+				if ($data["new"]["autoresponder_start_date"] != '0000-00-00 00:00:00') { // Dates have been set
+					$tpl = str_replace('{start_date}',strtotime($data["new"]["autoresponder_start_date"]),$tpl);
+					$tpl = str_replace('{end_date}',strtotime($data["new"]["autoresponder_end_date"]),$tpl);
+				} else {
+					$tpl = str_replace('{start_date}',-7200,$tpl);
+					$tpl = str_replace('{end_date}',2147464800,$tpl);
+				}
+				
 				// Write the config file.
 				$config_file_path = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.autoresponder';
 				file_put_contents($config_file_path,$tpl);
@@ -137,12 +165,11 @@
 			}
 		}
 			
-			$app->log("HERE",LOGLEVEL_DEBUG);
-			
 			// Write the custom mailfilter script, if mailfilter recipe has changed
-			if($data["old"]["custom_mailfilter"] != $data["new"]["custom_mailfilter"]) {
+			if($data["old"]["custom_mailfilter"] != $data["new"]["custom_mailfilter"] or
+			   $data["old"]["move_junk"] != $data["new"]["move_junk"]) {
 				$app->log("Mailfilter config has been changed",LOGLEVEL_DEBUG);
-				if(trim($data["new"]["custom_mailfilter"]) != '') {
+				if(trim($data["new"]["custom_mailfilter"]) != '' or $data["new"]["move_junk"] != 'n') {
 					// Delete the old filter recipe
 					$email_parts = explode("@",$data["old"]["email"]);
 					$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.mailfilter';
@@ -155,7 +182,14 @@
 						$email_parts = explode("@",$data["old"]["email"]);
 					}
 					$config_file_path = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.mailfilter';
-					file_put_contents($config_file_path,$data["new"]["custom_mailfilter"]);
+					
+					$mailfilter_content = '';
+					if($data["new"]["move_junk"] == 'y') {
+						$mailfilter_content .= file_get_contents($conf["rootpath"].'/conf/mailfilter_move_junk.master')."\n";
+					}
+					$mailfilter_content .= $data["new"]["custom_mailfilter"];
+					
+					file_put_contents($config_file_path,$mailfilter_content);
 					$app->log("Writing new custom Mailfiter".$config_file_path,LOGLEVEL_DEBUG);
 					exec("chmod 770 $config_file_path");
 					exec("chown vmail $config_file_path");
@@ -192,6 +226,10 @@
 			if(is_file($file)) unlink($file)  or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
 			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.mailfilter';
 			if(is_file($file)) unlink($file)  or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
+			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst.gdbm';
+			if(is_file($file)) unlink($file)  or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
+			$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.vacation.lst.lock';
+			if(is_file($file)) unlink($file)  or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
 			rmdir($dir) or $app->log("Unable to delete directory: $dir",LOGLEVEL_WARN);
 		}
 	}

--
Gitblit v1.9.1