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