summaryrefslogtreecommitdiffstats
path: root/web/attachments/76454-check_pop3.diff
blob: 3e50a1433a88eba7f1519c780d2f7dcf9bb5345d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
--- check_pop3.pl	2004-01-05 16:43:27.000000000 -0600
+++ /home/jason/sf/nagiosplug/contrib/check_pop3.pl	2002-02-28 00:42:53.000000000 -0600
@@ -23,29 +23,6 @@
 #				with perl -wT and 'use strict'
 # 2000/01/20	RM		Corrected POP3 Exit State.
 # 2000/01/21	RM		Fix Exit Codes Again!!
-# 2003/12/30	CZ		Proper CRLF in communication w/server
-#				Fixed infinite loop
-#				Error checking on welcome banner, USER, PASS commands
-#				Better error condition handling
-#				This could probably be much much smaller using Net::POP3,
-#				but I haven't looked into its error conditions yet, and I
-#				don't think you can specify remote port.
-
-=cut
-
-use Net::POP3;
-
-my $pop = new Net::POP3("$ARGV[0]", Timeout => 60);
-my $ret = $pop->login("$ARGV[1]","$ARGV[2]");
-$pop->quit();
-
-do { print "some error msg\n"; exit 2; } unless defined $ret;
-
-print "POP3 OK - ".int($ret)." messages\n";
-exit 0;
-
-=cut
-
 # ------------------------------------------------------------------------------
 
 # -----------------------------------------------------------------[ Require ]--
@@ -120,56 +97,47 @@
 	my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname);
 	
 
-	err("no welcome banner\n") unless $_ = <ClientSocket>;
-	err("bad welcome banner: " . $_) unless $_ =~ /^\+OK/;
+print ClientSocket "user $username\n";
 
-	print ClientSocket "USER $username\r\n";
+#Debug Server
+#print "user $username\n";
 
-	#Debug Server
-	#print "user $username\n";
+#Sleep or 3 secs, incase server is slow.
+sleep 3;
 
-	err("no response to USER command\n") unless $_ = <ClientSocket>;
-	err("bad response to USER: " . $_) unless $_ =~ /^\+OK/;
+print ClientSocket "pass $password\n";
 
-	print ClientSocket "PASS $password\r\n";
+#Debug Server
+#print "pass $password\n";
 
-	#Debug Server
-	#print "pass $password\n";
+while (<ClientSocket>) {
 
-	err("no response to PASS command\n") unless $_ = <ClientSocket>;
-	err("bad response to PASS: " . $_) unless $_ =~ /^\+OK/;
+print ClientSocket "pass $password\n";
 
-	print ClientSocket "LIST\r\n";
+#Debug Server
+#print $_;
 
-	my $bad = 1;
-	my $msgs = 0;
-	while (<ClientSocket>) {
-		#Debug Server
-		#print $_;
-
-		err(($1||' UNKNOWN')."\n") if (m/\-ERR(.*)/);
-		$bad = 0 if /^\+OK/;
-		$msgs = $1 if /^(\d+)\s+/;
-		last if /^\./;
-	}
-	&message("$msgs\n") unless $bad;
-	err("missing +OK to LIST command\n");
+err($_) if (m/\-ERR\s+(.*)\s+.*/);
+message($_) if (m/\+OK Mailbox open,\s+(.*\d)\s+messages.*/);
+}
 }
 
 sub message 
 {
-  	my $answer = "POP3 OK - Total Messages On Server: ".shift();	
+	my $answer = "UNKNOWN";
+  	$answer = "Pop3 OK - Total Messages On Server :- $1";	
 	alarm(0);
-	print ClientSocket "QUIT\r\n";
+	print ClientSocket "quit\n";
 	print "$answer";
 	exit 0;
 }
 
 sub err
 {
-	my $answer = "POP3 Error:".shift();
+	my $answer = "UNKNOWN";
+	$answer = "Pop3 Error :- $1";
 	alarm(0);
-	print ClientSocket "QUIT\r\n";
+	print ClientSocket "quit\n";
 	print "$answer";
 	exit 2;
 }