Guest User

Untitled

a guest
Apr 8th, 2018
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.72 KB | None | 0 0
  1. <?php
  2.  
  3. if (empty($_POST['user']) OR empty($_POST['pass']) OR !isset($_POST['user']) OR !isset($_POST['pass'])) {
  4.     die("Проверить почту невозможно, т.к. введены не все данные!<br><a href='index.html'>Назад</a>");
  5.     }
  6.  
  7. $user = $_POST['user']; //ZABOEBATEJLb@mail.ru
  8. $pass = $_POST['pass'];
  9. $server = "pop.mail.ru";
  10.  
  11. function from_detector($text) {
  12. $pattern_from = "/(?<=From:\s).*/";
  13. preg_match($pattern_from, $text, $from);
  14. return $from[0];
  15. }
  16.  
  17. //function subject_detector($text) {
  18. //$pattern_subject = "/(?<=Subject:\s).*/";
  19. //preg_match($pattern_subject, $text, $subject);
  20. //return implode($subject);
  21. //}
  22.  
  23. //колбэк функция для preg_replace_callback
  24. function decode_match($matches)
  25. {
  26.     $encoding = strtolower($matches[1]);
  27.     $type = strtolower($matches[2]);
  28.     $string = $matches[3];
  29.  
  30.     if($type == 'b')
  31.     {
  32.         $string = base64_decode($string);
  33.     }
  34.     else
  35.     {
  36.         $string = quoted_printable_decode(str_replace('_', '', $mystring));
  37.     }
  38.  
  39.     if($encoding != 'windows-1251')
  40.     {
  41.         $string = iconv($encoding, "WINDOWS-1251", $string);
  42.     }
  43.  
  44.     return $string;
  45. }
  46.  
  47. function decode_mime($string, $type, $encoding)
  48. {
  49.     $encoding = strtolower($encoding);
  50.     $type = strtolower($type);
  51.  
  52.     if($type == 'b')
  53.     {
  54.         $string = base64_decode($string);
  55.     }
  56.     else
  57.     {
  58.         $string = quoted_printable_decode(str_replace('_', '', $mystring));
  59.     }
  60.  
  61.     if($encoding != 'windows-1251')
  62.     {
  63.         $string = iconv($encoding, "WINDOWS-1251", $string);
  64.     }
  65.  
  66.     return $string;
  67. }
  68.  
  69. function get_subject($text)
  70. {
  71.     $subject = strstr($text, 'Subject:');
  72.  
  73.     if($subject === FALSE)
  74.     {
  75.         return FALSE;
  76.     }
  77.  
  78.     $subject = substr($subject, 9);
  79.     $subject_new = $subject;
  80.     $result = '';
  81.  
  82.     do
  83.     {
  84.         preg_match('/^=\?([^?]+)\?((?i)b|q)\?([^?]+)\?=/', $subject_new, $matches);
  85.  
  86.         if(!empty($matches))
  87.         {
  88.             $result .= decode_mime($matches[3], $matches[2], $matches[1]);
  89.         }
  90.  
  91.         $break_pos = strpos($subject_new, chr(13));
  92.         $subject_new = ltrim(substr($subject_new, $break_pos + 2));
  93.     } while(!empty($matches));
  94.  
  95.     if(empty($result))
  96.     {
  97.         $result = substr($subject, 0, $break_pos + 1);
  98.     }
  99.  
  100.     return $result;
  101. }
  102.  
  103.  
  104. function read_socket($socket){
  105. stream_set_blocking($socket, 1);
  106. $data="";
  107. while (!feof($socket)) {
  108.     $buffer = fgets($socket, 512);
  109.     if ($buffer == false) {
  110.     break;
  111.     }
  112.     $data .= "$buffer\r\n";
  113. }
  114. return $data;
  115. }
  116.  
  117. $socket = fsockopen($server, 110, $errno, $errstr, 30);
  118. stream_set_timeout($socket, 6);
  119.  
  120. if (!$socket) {
  121.     die($errstr. "($errno)<br />\n");
  122. }
  123.  
  124. $res = fgets($socket, 100);
  125. if (substr(trim($res), 0, 3) != "+OK") {
  126.     die($res);
  127. }
  128.  
  129. fputs($socket, "USER $user\r\n");
  130. $res = fgets($socket, 100);
  131. if (substr(trim($res), 0, 3) != "+OK") {
  132.     die($res);
  133. }
  134.  
  135. fputs($socket, "PASS $pass\r\n");
  136. $res = fgets($socket, 100);
  137. if (substr(trim($res), 0, 3) != "+OK") {
  138.     die($res);
  139. }
  140.  
  141. echo "Проверка почты...<br>\r";
  142.  
  143. fputs($socket, "STAT\r\n");
  144. $mails = fgets($socket, 15);
  145. if (substr(trim($mails), 0, 3) != "+OK") {
  146.     die($mails);
  147. }
  148. else $mails = intval(substr_replace($mails, "", 0, 4));
  149. echo "Писем в ящике ".$user.": ".$mails."<br><br>\r";
  150.  
  151. for ($i = 1; $i <= $mails; $i++) {
  152. fputs($socket, "TOP $i 1\r\n");
  153. $mail = fgets($socket, 6);
  154. if (substr(trim($mail), 0, 3) != "+OK") {
  155.     die($mail);
  156.     }
  157.     else $mail = read_socket($socket);
  158.     $subject = get_subject($mail);
  159.     $from = decode_mime(from_detector($mail));
  160. echo "Письмо ".$i.": ".$subject." от ".$from."<hr>";
  161. }
  162. fputs($socket, "QUIT\r\n");
  163. fclose($socket);
  164.  
  165. ?>
Add Comment
Please, Sign In to add comment