note 51363 deleted from function.fsockopen by cmb
| From: | cmb@php.net | Date: | Sun, 07 Jul 2019 07:53:37 +0000 |
| Subject: | note 51363 deleted from function.fsockopen by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211496@lists.php.net to get a copy of this message | ||
Note Submitter: ahauk at NO-SPAM dot synergynt dot net
----
The following script will login to a POP3 account using the username, password and server name
provided via a standard form; determine the amount of messages using a binary search; then purge all
messages.
<?php
$server = $_POST["server"];
$user = $_POST["user"];
$pass = $_POST["pass"];
$count = 1;
$low = 0;
$mid = 0;
$high = 100000;
$connection = fsockopen($server, 110, $errno, $errstr, 30);
if(!$connection) {
print "Connect Failed: $errstr ($errno)";
} else {
$output = fgets($connection, 128);
fputs($connection, "user $user\n");
$output = fgets($connection, 128);
fputs($connection, "pass $pass\n");
$output = fgets($connection, 128);
while($low < $high - 1) {
$mid = floor(($low + $high) / 2);
fputs($connection, "list $mid\n");
$output = fgets($connection, 128);
$subout = substr($output, 0, 4);
if($subout == "+OK ") {
$low = $mid;
continue;
}
elseif($subout == "-ERR") {
$high = $mid;
continue;
} else {
break;
print "An error has occurred. Please try again.";
}
}
$limit = $mid - 1;
while($count <= $limit) {
fputs($connection, "dele $count\n");
fgets($connection, 128);
$count = $count + 1;
}
fputs($connection, "quit\n");
}
fclose($connection);
print "Successfully removed $limit messages.";
?>