From e94a9fb5e4b6a2bc07e0bb4cf8ea35fc70c4bbf0 Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Thu, 10 May 2012 12:31:27 -0400
Subject: [PATCH] Merged revisions 3049-3051,3053-3054,3058,3070,3074-3077,3082,3086-3088,3091-3092,3094-3095 from stable branch.

---
 server/plugins-available/maildrop_plugin.inc.php |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/server/plugins-available/maildrop_plugin.inc.php b/server/plugins-available/maildrop_plugin.inc.php
index 998b7c4..085a992 100644
--- a/server/plugins-available/maildrop_plugin.inc.php
+++ b/server/plugins-available/maildrop_plugin.inc.php
@@ -60,6 +60,7 @@
 		Register for the events
 		*/
 		
+		$app->plugins->registerEvent('mail_user_insert','maildrop_plugin','update');
 		$app->plugins->registerEvent('mail_user_update','maildrop_plugin','update');
 		$app->plugins->registerEvent('mail_user_delete','maildrop_plugin','delete');
 		
@@ -124,7 +125,7 @@
 			$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($ar_file) or $app->log("Unable to delete file: $ar_file",LOGLEVEL_WARN);
+			if(is_file($file)) unlink($file) or $app->log("Unable to delete file: $file",LOGLEVEL_WARN);
 			
 			
 			//Now we create the new autoresponder, if it is enabled
@@ -165,13 +166,16 @@
 			}
 		}
 			
-			// Write the custom mailfilter script, if mailfilter recipe has changed
-			if($data["old"]["custom_mailfilter"] != $data["new"]["custom_mailfilter"]
-			   or $data["old"]["move_junk"] != $data["new"]["move_junk"]
-			   or $data["old"]["cc"] != $data["new"]["cc"]) {
+		// Write the custom mailfilter script, if mailfilter recipe has changed
+		if($data["old"]["custom_mailfilter"] != $data["new"]["custom_mailfilter"]
+			or $data["old"]["move_junk"] != $data["new"]["move_junk"]
+			or $data["old"]["cc"] != $data["new"]["cc"]) {
 			   
 				$app->log("Mailfilter config has been changed",LOGLEVEL_DEBUG);
-				if(trim($data["new"]["custom_mailfilter"]) != '' or $data["new"]["move_junk"] != 'n') {
+				if(trim($data["new"]["custom_mailfilter"]) != '' 
+					or $data["new"]["move_junk"] != 'n' 
+					or $data["new"]["cc"] != '') {
+					
 					// Delete the old filter recipe
 					$email_parts = explode("@",$data["old"]["email"]);
 					$file = $this->mailfilter_config_dir.'/'.$email_parts[1].'/'.$email_parts[0].'/.mailfilter';
@@ -189,6 +193,7 @@
 					
 					if($data["new"]["cc"] != '') {
 						$mailfilter_content .= "cc \"!".$data["new"]["cc"]."\"\n";
+						$app->log("Added CC address ".$data["new"]["cc"].' to mailfilter file.',LOGLEVEL_DEBUG);
 					}
 					
 					if($data["new"]["move_junk"] == 'y') {
@@ -206,12 +211,15 @@
 					unset($config_file_path);
 				} else {
 					// Delete the mailfilter recipe
-					$email_parts = explode("@",$data["old"]["email"]);
-					$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);
-					$app->log("Deleting custom Mailfiter".$file,LOGLEVEL_DEBUG);
+					if(isset($data["old"]["email"])) {
+						$email_parts = explode("@",$data["old"]["email"]);
+						$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);
+							$app->log("Deleting custom Mailfiter".$file,LOGLEVEL_DEBUG);
+						}
+					}
 				}
-			//}
 		}
 	}
 	

--
Gitblit v1.9.1