понедельник, 22 ноября 2010 г.

Удаление все писем из ящика на PHP

Purge / delete all emails from a POP server in PHP.

If you have a POP3 account which has been spammed to death, and being on dial-up you are unable to get in and delete all the messages, this handy script will delete all the messages on your POP server. There is no reason why this could not be modified to delete only messages over a certain size or even with some more modification to delete messages with specific content.

Note: There is no working example as the potential for misuse on this server makes it insecure.

// So, username is your POP3 $username, password is your $password

$cmd = array();
$cmd[] = "USER $username\r\n";
$cmd[] = "PASS $password\r\n";
$cmd[] = "STAT\r\n";
$cmd[] = "QUIT\r\n";

// Server is your POP3 server, ie pop3.server.com
// Port is the port number ( should be 110 )

$port = 110;

$fp = fsockopen($server, $port);
if(!
$fp)
{
print(
"Error connecting to server $server");
}
else
{
$ret = fgets($fp, 1024);
foreach(
$cmd as $ret)
{
fputs($fp,$ret);
$line = fgets($fp, 1024);
print(
$line."
"
);
if(
$ret=="STAT\r\n")
{
$fields = explode(" ",$line);
$num_mails = $fields[1];
for(
$i=1;$i<=$num_mails;$i++)
{
fputs($fp,"DELE $i\r\n");
$line = fgets($fp, 1024);
}
}
}
}
?>

Комментариев нет:

Отправить комментарий