I log all cron jobs to a single email account from multi domains. So have found the need to tidy this process up. By changing a script i had laying arund to delete all emails but leave 9 worked but I would like a way to make this more dynamic and delete emails based on x days old.
I dont care about subject or anything else I just want to keep the last 7 days emails.
[code]
if(!$sock=fsockopen($host, 110, $err, $errno, 10))
die(“Couldn’t connect to the POP server$nl”);
fputs($sock, “USER $userrn”);
$buf = fgets($sock, 1024);
if($buf[0] != ‘+’)
die(“POP server didn’t like USER $user$nl”);
fputs($sock, “PASS $passrn”);
$buf = fgets($sock, 1024);
if($buf[0] != ‘+’)
die(“POP server didn’t like PASS$nl”);
fputs($sock, “STATrn”);
$buf = fgets($sock, 1024);
fputs($sock, “STATrn”);
$buf2 = fgets($sock, 1024);
list($stat, $num, $size) = split(‘ ‘, $buf2, 3);
echo “There are $num messages$nl”;
if($num<=10)
die(“Quitting – Less than 10 emails”);
for($i=1; $i<=$num-10; $i++){
$command = “DELE $irn”;
echo “Deleting message $i with DELE $i$nl”;
fputs($sock, $command);
$buf = fgets($sock, 1024);
if($buf[0] != ‘+’)
die(“POP server didn’t like DELE $i: ($buf)$nl”);
}
Cheers