หน้าแรก / Programing / PERL / zpop cli check pop3

 

#!/usr/bin/perl
use Getopt::Long;
use Net::POP3;
use Data::Dumper;

my $debug=’0′;
my $port=’25′;

sub pop3_mail {

my ($mailhost, $user, $pass, $port, $type, $debug);

$mailhost = shift;
$user = shift;
$pass = shift;
$port = shift;
$type = shift;
$debug = shift;
# $pop = Net::POP3->new($maihost);
$pop = Net::POP3->new($mailhost, Timeout => 60,Debug => $debug);
if(!defined($pop) || !($pop))
{
print “POP3 ERROR: Unable to open POP3 session.\n”;
exit 1;
}

if ($pop->login($user, $pass) > 0) {
my @pstat = $pop->popstat;
print Dumper(@pstat);
# my $msgnums = $pop->list; # hashref of msgnum => size
# foreach my $msgid (keys %$msgnums) {
# print $msgid . “> “;
# $head = $pop->top($msgid,0);
# print @$head;
# $pop->delete($msgnum);
#}
}else{
print “POP3 ERROR: Authentication Fail !!”;
}

$pop->quit;

}

sub synctex {
print “Usage: zpop.pl\n”;
print “\t-u {username}\n”;
print “\t-p {password}\n”;
print “\t-c {port} \n”;
print “\t-t {tls|ssl}\n “;
print “\t-h {host}\n”;
print “\t-d {0|1}\n”;

}
GetOptions (“username=s” => \$user, # string
“password=s” => \$pass, # string
“connect=s” => \$port, # flag
“type=s” => \$type,
“host=s” => \$host,
“debug=i” => \$debug) #integer
or die(“Error in command line arguments\n”);

 

if(! defined ($user && $pass && $host )){
synctex();
}else {
# print $host . $user .$pass .$port .$type . $debug;
pop3_mail ($host, $user, $pass, $port, $type, $debug);
}

 
 
 

Add a comment

required

required

optional