Last active
April 25, 2020 13:12
-
-
Save mcrmonkey/504004ff3339dd5a4038f98275ab5589 to your computer and use it in GitHub Desktop.
perl script to login to a popbox and do stuff for mail from certain places
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Net::POP3; | |
use strict; | |
my %pop3 = ( | |
"Usrname" => '', | |
"Passwd" => '', | |
#### Diagnostics: | |
"DEBUG" => '1', ## basic debug messages | |
"DEBUG2" => '1', ## show msgs | |
"DELEM" => '1', ## delete messages from server | |
); | |
my $pop = Net::POP3->new('mailhost', Timeout => 60) or die "Connection to mail server failed"; | |
my $totalmsgs = $pop->login($pop3{Usrname}, $pop3{Passwd}); | |
if ($pop3{DEBUG}) {printf "there are $totalmsgs in the box \n";}; | |
if ($totalmsgs > 0) { | |
my $msgnums = $pop->list; # hashref of msgnum => size | |
foreach my $msgnum (keys %$msgnums) { | |
my $msg = $pop->get($msgnum); | |
if ($pop3{DEBUG2}) {print @$msg; printf "<END>\n";}; | |
process_Message ($msg); | |
if ($pop3{DELEM}) {$pop->delete($msgnum);}; | |
} | |
} else { | |
if ($pop3{DEBUG}) {printf "There were no messages in the mailbox\n";}; | |
} | |
$pop->quit; | |
sub process_Message { | |
my $Message_array_ref = shift; | |
my $Message = join "", @$Message_array_ref; | |
my ($subject) = $Message =~ /Subject: (.*)/m; | |
my ($from ) = $Message =~ /From: (.*)/m; | |
my ($status ) = $Message =~ /Status: (.*)/m; | |
printf "\n"; | |
if ($from eq "Nagios <nagios>") { | |
printf "Nagios\n"; | |
}; | |
if ($from eq "scom") { | |
printf "scom\n"; | |
my ($state ) = $Message =~ /X-STATE: (.*)/m; | |
printf "\n $state "; | |
}; | |
if ($from eq "<vcenter>") { | |
printf "Vcenter\n"; | |
}; | |
}; | |
printf "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment