/    Sign up×
Community /Pin to ProfileBookmark

Delete old POP3 emails

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”);
}
[/code]

Cheers

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @p_lea spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...