Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (empty($_POST['user']) OR empty($_POST['pass']) OR !isset($_POST['user']) OR !isset($_POST['pass'])) {
- die("Проверить почту невозможно, т.к. введены не все данные!<br><a href='index.html'>Назад</a>");
- }
- $user = $_POST['user']; //ZABOEBATEJLb@mail.ru
- $pass = $_POST['pass'];
- $server = "pop.mail.ru";
- function from_detector($text) {
- $pattern_from = "/(?<=From:\s).*/";
- preg_match($pattern_from, $text, $from);
- return $from[0];
- }
- //function subject_detector($text) {
- //$pattern_subject = "/(?<=Subject:\s).*/";
- //preg_match($pattern_subject, $text, $subject);
- //return implode($subject);
- //}
- //колбэк функция для preg_replace_callback
- function decode_match($matches)
- {
- $encoding = strtolower($matches[1]);
- $type = strtolower($matches[2]);
- $string = $matches[3];
- if($type == 'b')
- {
- $string = base64_decode($string);
- }
- else
- {
- $string = quoted_printable_decode(str_replace('_', '', $mystring));
- }
- if($encoding != 'windows-1251')
- {
- $string = iconv($encoding, "WINDOWS-1251", $string);
- }
- return $string;
- }
- function decode_mime($string, $type, $encoding)
- {
- $encoding = strtolower($encoding);
- $type = strtolower($type);
- if($type == 'b')
- {
- $string = base64_decode($string);
- }
- else
- {
- $string = quoted_printable_decode(str_replace('_', '', $mystring));
- }
- if($encoding != 'windows-1251')
- {
- $string = iconv($encoding, "WINDOWS-1251", $string);
- }
- return $string;
- }
- function get_subject($text)
- {
- $subject = strstr($text, 'Subject:');
- if($subject === FALSE)
- {
- return FALSE;
- }
- $subject = substr($subject, 9);
- $subject_new = $subject;
- $result = '';
- do
- {
- preg_match('/^=\?([^?]+)\?((?i)b|q)\?([^?]+)\?=/', $subject_new, $matches);
- if(!empty($matches))
- {
- $result .= decode_mime($matches[3], $matches[2], $matches[1]);
- }
- $break_pos = strpos($subject_new, chr(13));
- $subject_new = ltrim(substr($subject_new, $break_pos + 2));
- } while(!empty($matches));
- if(empty($result))
- {
- $result = substr($subject, 0, $break_pos + 1);
- }
- return $result;
- }
- function read_socket($socket){
- stream_set_blocking($socket, 1);
- $data="";
- while (!feof($socket)) {
- $buffer = fgets($socket, 512);
- if ($buffer == false) {
- break;
- }
- $data .= "$buffer\r\n";
- }
- return $data;
- }
- $socket = fsockopen($server, 110, $errno, $errstr, 30);
- stream_set_timeout($socket, 6);
- if (!$socket) {
- die($errstr. "($errno)<br />\n");
- }
- $res = fgets($socket, 100);
- if (substr(trim($res), 0, 3) != "+OK") {
- die($res);
- }
- fputs($socket, "USER $user\r\n");
- $res = fgets($socket, 100);
- if (substr(trim($res), 0, 3) != "+OK") {
- die($res);
- }
- fputs($socket, "PASS $pass\r\n");
- $res = fgets($socket, 100);
- if (substr(trim($res), 0, 3) != "+OK") {
- die($res);
- }
- echo "Проверка почты...<br>\r";
- fputs($socket, "STAT\r\n");
- $mails = fgets($socket, 15);
- if (substr(trim($mails), 0, 3) != "+OK") {
- die($mails);
- }
- else $mails = intval(substr_replace($mails, "", 0, 4));
- echo "Писем в ящике ".$user.": ".$mails."<br><br>\r";
- for ($i = 1; $i <= $mails; $i++) {
- fputs($socket, "TOP $i 1\r\n");
- $mail = fgets($socket, 6);
- if (substr(trim($mail), 0, 3) != "+OK") {
- die($mail);
- }
- else $mail = read_socket($socket);
- $subject = get_subject($mail);
- $from = decode_mime(from_detector($mail));
- echo "Письмо ".$i.": ".$subject." от ".$from."<hr>";
- }
- fputs($socket, "QUIT\r\n");
- fclose($socket);
- ?>
Add Comment
Please, Sign In to add comment