Any script can clear spam box automatically ?

jameshsi

Well-Known Member
Oct 22, 2001
347
0
316
HI! Pal:
Is there any script can do this for me ?
Set a crontab job and it can clear the users who had actived the spam box for us, if you have made a script like this for yourself can you let me have it ?

Thanks and Merry X'mas.
 

lloyd_tennison

Well-Known Member
Mar 12, 2004
698
1
168
The very nature of the spambox is to have it set to delete after a certain peiod of time, making any cron or such not needed as it is handled on a per mail account basis.
 

WebScHoLaR

Well-Known Member
Dec 14, 2005
510
3
168
Planet Earth
jameshsi said:
HI! Pal:
Is there any script can do this for me ?
Set a crontab job and it can clear the users who had actived the spam box for us, if you have made a script like this for yourself can you let me have it ?

Thanks and Merry X'mas.
You can setup a cron job as mentioned below to clear the spam box for the email accounts.

> /home/username/mail/domain.com/emailaccount/spam
 

pphillips

Well-Known Member
Nov 14, 2003
71
0
156
To dump spam automatically domain wide you can run a script I wrote via cron. You can download the latest copy of it at http://www.phillipsdata.com/phpscripts/dumpspam.txt

Here is the code as of this writing:

PHP:
#!/usr/bin/php -q
<?

/*
*  Written by Paul Phillips, phillipsdata.com
*  Distribute or modify freely, but please give me credit for this code in any 
*  derivative works. Please do not remove these comments.
*/

function dumpallspam() {
	$domain = "yourdomain.com";
	$cpaneluser = "yourcpaneluser";
	$cpanelpass = "yourcpanelpass";
	$cpaneltheme= "x"; // The cpanel theme used. in the url it appears after :2082/frontend/ <-- here

	// First do a check if curl_init exists:
	if (function_exists("curl_init")) {
		$authstr = "$cpaneluser:$cpanelpass";

		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $domain . ":2082/frontend/" . $cpaneltheme . "/mail/clearspambox.html?");
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_USERPWD, $authstr);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,1);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,1);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

		$cbsreturn = curl_exec($ch);
		//echo "Result: " . $cbsreturn; // Returns all the html from cpanel, uncomment to view
		//die;
		if (strpos($cbsreturn, "spambox has been cleared")) {
			return true;
		} else {
			return false;
		}

		// debug echo curl_error($ch);
		curl_close($ch);
	}
}

if (dumpallspam()) {
	// dont echo anything if via cron cause we dont want emails! echo "Dumped spam ok";
} else {
	echo "problem dumping spam, check the settings!";
}

?>
Enjoy!
 

pphillips

Well-Known Member
Nov 14, 2003
71
0
156
That's a good question. I think it can be done with each domains username and the root password. We would just need to loop through what we do now in the script I posted with an array of every username on the server. We could probably read the quotas file on the server to get this list of usernames. The script would need to be run from cron via root user.

I don't have the time to code something like this for free at the moment, but I would be willing to do this for money.
 

bmcgrail

Well-Known Member
Dec 8, 2003
83
0
156
Below is a simple script I made to find all spam folders on my server and remove any messages 7 days or older. You can easily change it to 30 days if you wish.

This script is for Maildir. If you are running mbox this will not work.

create a file called /root/del_spam (or whatever you like)
Add the following to the file

Code:
#/bin/sh
/usr/bin/find /home/*/mail/*/*/.spam/*/ -type f -ctime +6 | xargs /bin/rm -v
The -v will output a list of all files removed. Good for testing. You can take out at a later time. run without | xargs /bin/rm to see what files are found without removing them.

How it works: The find command looks for Maildir Spam as stored in:
/home/account/mail/domainname/username/.spam/(cur | new)/file
/home/*......../mail/*.............../*.........../.spam/*

Run nightly from cron

# crontab -e
10 0 * * * /root/del_spam
 

jameshsi

Well-Known Member
Oct 22, 2001
347
0
316
Thanks a lot, but my problem is, most people forget to delete and their quota been used up, so, I do it below:

Code:
#/bin/sh
/usr/bin/find /home/*/mail/*/*/spam -type f  -size +12000k | xargs /bin/rm -v