added tips to lamer.bash help
[mirrors/Programs.git] / php / skripty / mailcheck.php
1 <?php
2 $serv = "pop3.seznam.cz";
3 $port = "110";
4 $mail = "harvie@seznam.cz";
5 $pass = "harddaysnight";
6 $delay = 5;
7
8 ///FUNCS///////////////////////////////////////////////////////////////
9
10 function pop3_connect($mail, $pass, $serv, $port=110) {
11 $fserv = fsockopen($serv, $port);
12 if(!$fserv) return -1; //Cannot connect
13 $resp = fgets($fserv); //echo($resp); //Debug
14 $request = "USER $mail\nPASS $pass\n";
15
16 fwrite($fserv, $request);
17 $resp = fgets($fserv); if (!eregi("\\+", $resp)) return -2; //Bad username
18 //echo($resp);
19 $resp = fgets($fserv); if (!eregi("\\+", $resp)) return -3; //Bad password
20 //echo($resp);
21
22 return($fserv);
23 }
24
25 function pop3_cmd($fserv, $cmd) {
26 $request = "$cmd\n";
27 fwrite($fserv, $request);
28 return trim(fgets($fserv));
29 }
30
31 function pop3_check($fserv) {
32 echo($fserv."\n");
33 switch($fserv) {
34 case -1: echo("Cannot conect!\n"); break;
35 case -2: echo("Bad username!\n"); break;
36 case -3: echo("Bad password!\n"); break;
37 }
38 }
39
40 function pop3_unread($fserv) {
41 $resp = pop3_cmd($fserv, "STAT");
42 $resp = explode(" ", $resp);
43 return trim($resp[1]);
44 }
45
46 function pop3_quit($fserv) {
47 pop3_cmd($fserv, "QUIT");
48 fclose($fserv);
49 }
50 ///CODE/////////////////////////////////////////////
51
52
53 //pop3_check($fserv);
54 //echo pop3_cmd($fserv, "STAT")."\n";
55
56 $last_unread = 0;
57 while(1) {
58 if(!isset($fserv) || !$fserv) {
59 $fserv = pop3_connect($mail, $pass, $serv, $port);
60 }
61
62 $unread = pop3_unread($fserv);
63 if($unread != $last_unread && $unread != "") {
64 echo("You have $unread messages!\n");
65 $last_unread = $unread;
66 }
67
68 pop3_quit($fserv);
69 sleep($delay);
70 }
71
72 /*
73 USER harvie@seznam.cz
74 PASS harddaysnight
75 */
76
77 /*
78 +OK Hello, this is Seznam POP3 server 2.3.16.
79 USER harvie@seznam.cz
80 PASS harddaysnight
81 +OK Enter your password please.
82 +OK 79 1298041
83 */
This page took 0.947636 seconds and 4 git commands to generate.