• Inviting everyone who uses WordPress management tools in Plesk
    The Plesk team is conducting a 60-minute research session that includes an interview and a moderated usability test.
    To participate, please use this link .
    Your experience will help shape product decisions and ensure the tools better support real-world use cases.

An alternative to qmHandle - a PHP Based Qmail Queue Spam Cleaner

C

criticman

Guest
For some reason, qmHandle randomly stopped working.

So, I wrote a replacement in PHP to meet my needs. All it does is delete messages containing a string of your choosing. It deletes the message, the info & remote files too.

Pretty basic, but it got the job done.

Details:
http://blog.criticman.com/2006/06/05/php-based-qmail-queue-spam-cleaner/

And here is the code:
PHP:
<?php
	/* Qmail-Queue-Cleaner.php
		Written by Matthew R Williams aka Criticman
		blog.criticman.com
		Some rights reserved.
		Please contact me if you wish to use this base code in an altered form and distribute it.
		All others welcome to use and alter for personal use (or commercial use - just do not sell it for a profit).
	*/
	
	echo "Qmail-Queue-Cleaner.php written by Criticman.\nhttp://blog.criticman.com\n\n";

	/* BEGIN USER CONFIGURATION */
	$spamLine = "/failure/"; // line of spam you want to look for in each message, in this case, 'failure'
	$messDir = "/var/qmail/queue/mess"; // location of qmail 'mess' directory
	/* END USER CONFIGURATION */
	
	echo "Searching for: " . $spamLine . "\n\n";
	
	chdir($messDir); 
	echo "Starting in... " . getcwd() . "\n";
	$handle = opendir(".");
	while (false !== ($file = readdir($handle))) {
		if ($file != "." && $file != "..") { 
			chdir($file);
			echo "\tNow in... " . getcwd() . "\n";
			$myHandle = opendir(".");
			while (false !== ($myFile = readdir($myHandle))) {
				if ($myFile != "." && $myFile != "..") {
					$fh = fopen($myFile,'rb');
					$fContents = fread($fh,1024);
					if(preg_match($spamLine,$fContents) == 1) {
						fclose($fh);
						echo "Deleting file..." . $file . "/" . $myFile . " ...done.\n";
						unlink($myFile);
						unlink("/var/qmail/queue/info/$file/$myFile");
						unlink("/var/qmail/queue/remote/$file/$myFile");
					} else {
						fclose($fh);
					}
				}
			}
			chdir("..");
		}
	} 
	closedir($handle);
	echo "Process completed (hopefully).\n";
	exit;
?>
 
Back
Top