JaBbA's Hut :: Tickle Script
TicklerScript
| schoolmatchinfo3 | ticklerscript | Tickler Script Version 2 |
| ticklerscript |
This script has been updated. See version 2 for a much better version:
Note: This is still a work-in-progress. There are many things here which can be optimized. YMMV.
Requirements: crontab, shell, and an IMAP account.
This uses Maildirs. You'll need to refactor for mbox. Do not use without testing.
Note: a TODO hack. Emails placed directly into the 3Tickle folder are treated as todos - and as they age, the script starts yelling. They are ALWAYS listed.
#!/usr/bin/perl
use strict;
use Mail::Box::Manager;
use Mail::Box::Maildir;
my $debug=0;
my $MAIL="/home/jalcorn/Maildir/";
my $oneweek = 60*60*24*7;
my $onemonth = 60*60*24*30;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my @dayfolders = ("d01_7","d08_14", "d15_21","d22_31" );
my @monfolders = ("m01_Jan",
"m02_Feb",
"m03_Mar",
"m04_Apr",
"m05_May",
"m06_Jun",
"m07_Jul",
"m08_Aug",
"m09_Sep",
"m10_Oct",
"m11_Nov",
"m12_Dec",
);
sub print_tickle {
my $dir = shift;
my $text = shift;
my $mgr = new Mail::Box::Manager(default_folder_type=>'maildir');
my $todo = $mgr->open($MAIL.".3Tickle".$dir);
my @todos = $todo->messageIds;
if (!$dir) {
my $state = 4;
if ($#todos > -1) {
foreach (@$todo) {
my $ago = time() - $_->timestamp;
my $y = $year+1900;
my $dt = $abbr[$mon]." $mday, $y";
print "$dt\n" if $debug;
if ($ago > $onemonth && $state > 3) {
$state = 3;
print "\n*MORE THAN ONE MONTH OLD*\n";
} elsif ($ago > $oneweek * 2 && $state > 2) {
$state = 2;
print "\nTWO WEEKS\n";
} elsif ($ago > $oneweek && $state > 1) {
$state = 1;
print "\nOne Week:\n";
} elsif ($state > 0) {
$state = 0;
print "\nCurrent:\n";
}
print "\t",$_->subject,"\n";
}
}
} else {
if ($#todos > -1) {
print "\n".$text."\n";
foreach (@$todo) {
print "\t",$_->sender->format,": ",$_->subject,"\n";
}
}
}
$todo->close(write=>'NEVER');
}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time());
use integer;
my $wk = ($mday-1)/7;
print "Week is $wk\n" if $debug;
if ($wk > 3) {$wk = 3;}
my %wkend = (0=>7,1=>14,2=>21,3=>31);
my %monend = (0=>31,1=>28,2=>31,3=>30,4=>31,5=>30,6=>31,7=>31,8=>30,9=>31,10=>30,11=>31);
my $cwk = $wk;
my $y = $year+1900;
my $dt = $abbr[$mon]." $mday, $y";
print "Ticklers for $dt\n";
print_tickle("","");
for (my $i=0;$i<4;$i++) {
$cwk = $wk+$i;
if ($cwk > 3) {$cwk = $cwk-4;}
my $tickle = $i." Weeks";
if (!$i) {
print "Current Week\n" if $debug;
my $wkend=$wkend{$wk};
if ($wk == 3) {
$wkend=$monend{$mon};
}
print "Week End $wkend\n" if $debug;
$tickle = $wkend-$mday." Days";
}
print $cwk, $dayfolders[$cwk],"\n" if $debug;
print_tickle(".".$dayfolders[$cwk],$tickle);
}
for (my $i=1;$i<3;$i++) {
my $cm = $mon+$i;
if ($cm > 11) {$cm = $cm-12;}
print $cm, $monfolders[$cm],"\n" if $debug;
print_tickle(".".$monfolders[$cm],"Ticklers for ".$abbr[$cm]);
}


