Created
April 17, 2014 09:31
-
-
Save tryperl/10968561 to your computer and use it in GitHub Desktop.
Created by www.tryperl.com.
This file contains hidden or 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
#!/bin/perl | |
# Script to watch pop3 mailbox size. | |
#!/usr/bin/perl -w | |
use strict; | |
use warnings; | |
use Mail::POP3Client; | |
use Email::Date; | |
use Time::Piece; | |
use Time::Local; | |
use Email::Simple; | |
use DateTime; | |
use Date::Parse; | |
my $user = 'kontur'; | |
my $pass = 'fknthyfnbdf'; | |
print "signing in...\n"; | |
my $pop = new Mail::POP3Client( | |
USER => $user, | |
PASSWORD => $pass, | |
HOST => 'pop.ttb.ru', | |
PORT => 110, | |
); | |
my $count = $pop->Count(); | |
my $pop_size=$pop->Size(); | |
my $time= time; | |
my $time_2_file=localtime; | |
my $summ=0; | |
#my $temp=$ENV{temp}; | |
#my $logfile="\\\\server\\kuzmin\\documents\\mail.txt"; | |
#print "$logfile\n"; | |
#open (MYFILE, ">>",$logfile); | |
#my $capabilities=$pop->Capa(); | |
#print $capabilities; | |
print "-=-=-=-=-=-=-=-=-=-=-=-=-\n"; | |
print "$time_2_file\n"; | |
print "$pop_size byte(s)\n"; | |
my $tray_var="\"$time_2_file\""; | |
#print $temp_var; | |
if ($count < 0) { | |
$tray_var=$tray_var."\" $pop->Message()\""; | |
print "$pop->Message()\n"; | |
print "-=-=-=-=-=-=-=-=-=-=-=-=-\n"; | |
} elsif ($count == 0) { | |
$tray_var=$tray_var."\" $pop_size byte(s)\""."\" no messages\""; | |
print "no messages\n"; | |
print "-=-=-=-=-=-=-=-=-=-=-=-=-\n"; | |
} else { | |
$tray_var=$tray_var."\" $pop_size byte(s)\""."\" $count message(s)\""; | |
print "$count message(s)\n"; | |
if ($pop_size>=26600000){ | |
$tray_var=$tray_var."\" mailbox oversized!!!\""; | |
print "mailbox oversized!!!\n"; | |
for my $i (1 .. $count) { | |
#print "$i|"; | |
my $pop_header=$pop->Head($i); | |
my $simple_mail=Email::Simple->new($pop_header); | |
my $delivery_date=$simple_mail->header("Delivery-date"); | |
#print "delivery date is - $delivery_date\n"; | |
my ( $wday, $day, $month, $year, $hour, $min, $sec) = split /\W+/, $delivery_date; | |
#print "year before - 1900 $year\n"; | |
$year=$year-1900; | |
#print "year after - 1900 $year\n"; | |
my %mon2num = qw(jan 0 feb 1 mar 2 apr 3 may 4 jun 5 jul 6 aug 7 sep 8 oct 9 nov 10 dec 11); | |
#print "$wday $day $month $year $hour $min $sec\n"; | |
my $month1=$mon2num{ lc substr($month, 0, 3) }; | |
my $time_of_delivery = timelocal($sec,$min,$hour,$day,$month1,$year); | |
#print "time of delivery is - $time_of_delivery\n"; | |
my $msgnum; | |
my $size; | |
my $delta=$time-$time_of_delivery; | |
($msgnum, $size) = split('\s+', $pop -> List($i)); | |
#print "$delivery_date $size bytes\n"; | |
#print "delta is - $delta\n"; | |
if ($size>=102400 && $delta>=5400){ | |
$tray_var=$tray_var."\" Fat mail recieved at $delivery_date and huge as $size bytes! Be gone!\""; | |
print "Fat mail received at $delivery_date and huge as $size bytes! Be gone!\n"; | |
$pop->Delete($i); | |
}else{ | |
#$summ=$summ+$size; | |
} | |
} | |
} | |
$tray_var=$tray_var."\" All well, Master!\""; | |
print "All well, Master!\n"; | |
#print "$summ Bytes total\n"; | |
print "-=-=-=-=-=-=-=-=-=-=-=-=-\n"; | |
} | |
my $args="c:\\notify\\notifu64.exe"." /d 10"." /p $user"." /m $tray_var"; | |
#system ($args); | |
#close (MYFILE); | |
$pop->Close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment