+# Mails auf Festplatte speichern\r
+\r
+if(isset($store_mails) && $store_mails) {\r
+ # Betreff saeubern\r
+\r
+ $clean_subject = str_replace(' ','_',$subject);\r
+ $clean_subject = preg_replace('/[^a-z0-9\-_]/i','',$clean_subject);\r
+\r
+ # Eindeutigen Dateinamen der Mail zusammensetzen\r
+ \r
+ $file_name = $store_mails_dir.'/'.uniqid($store_mails_prefix.$email.'_'.$clean_subject.'_'.strftime('%d%m%Y-%H%M%S',$timestamp));\r
+ \r
+ # Daten in Datei schreiben\r
+ \r
+ file_put_contents($file_name,$mailtext);\r
+ \r
+ # Alte Dateien loeschen\r
+ \r
+ if(isset($store_mails_max) && $store_mails_max > 0) {\r
+ $dp = opendir($store_mails_dir);\r
+ \r
+ while($stored_mail_file = readdir($dp)) {\r
+ if($stored_mail_file != '.' && $stored_mail_file != '..' && substr($stored_mail_file,0,strlen($store_mails_prefix)) == $store_mails_prefix) {\r
+ $stored_mail_files[$store_mails_dir.'/'.$stored_mail_file] = filemtime($store_mails_dir.'/'.$stored_mail_file);\r
+ }\r
+ }\r
+ \r
+ closedir($dp);\r
+ \r
+ arsort($stored_mail_files);\r
+ \r
+ #print sizeof($stored_mail_files);\r
+ \r
+ #print_r($stored_mail_files);\r
+ \r
+ $x = 0;\r
+ \r
+ foreach(array_keys($stored_mail_files) as $stored_mail_filename) {\r
+ $x++;\r
+ \r
+ if($x > $store_mails_max) {\r
+ unlink($stored_mail_filename);\r
+ }\r
+ }\r
+ }\r
+}\r
+\r