JaBbA's Hut ::
Tickler Script, Ver 2
| ticklerscript | TOP | ebayphish |
| ticklerscript »Tickler Script Version 2 |
Here is my updated tickler script. Now uses The following IMAP Folder Structure:
- Inbox
- .1TODO
- .01
- .02
- ..etc..
- .m01_Jan
- .m02_Feb
- ..etc..
- .weekend
#!/usr/bin/perl
use Mail::Box::Manager;
use Mail::Box::Maildir;
$debug=0;
use integer;
$MAIL=(my maildir folder);
$TODO=$MAIL.".1TODO";
$oneweek = 60*60*24*7;
$onemonth = 60*60*24*30;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
my $mgr = new Mail::Box::Manager(default_folder_type=>'maildir');
my $todo = $mgr->open($MAIL.".1TODO");
@todos = $todo->messageIds;
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
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;
print "DIR: $dir TEXT: $text\n" if $debug;
my $mgr = new Mail::Box::Manager(default_folder_type=>'maildir',folderdir=>$MAIL);
print "Folderdir is ".$mgr->folderdir."\n" if $debug;
my $todo = $mgr->open($TODO.$dir."/",access=>'rw') or die "Cannot open $@";
my @todos = $todo->messageIds;
if (!$dir) {
#
# Print all the emails in the undated Todo file, under headings by age
#
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";
}
}
print "\n==============================\n\n";
} else {
#
# Print the upcoming ticklers, and move current ticklers into the Inbox
#
if ($#todos > -1) {
print "\n".$text."\n";
foreach (@$todo) {
print "\t",$_->sender->format,": ",$_->subject,"\n";
}
if ($text eq "Today") {
# This is today's folder
$mgr->copyMessage($MAIL,$todo->messages) or die "Cannot copy messages $@";
#
# N.B. - This says copy, but for some reason it moves with my server. YMMV
#
}
}
}
$todo->close or die 'Cannot close '.$todo->name;
}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time());
my $y = $year+1900;
my $dt = $abbr[$mon]." $mday, $y";
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);
print "Ticklers for $dt\n";
print_tickle("","");
for (my $i=0;$i<7;$i++) {
my $cday = $mday+$i;
if ($cday > $monend{$mon}) {$cday = $cday-$monend{$mon};}
my $dayfolder = sprintf("%02d",$cday);
my $tickle = $i ? $i." Days" : "Today";
print $cday, $dayfolder,"\n" if $debug;
print_tickle(".".$dayfolder,$tickle);
}
print_tickle(".weekend","This Weekend:");
my $cm = ($mon < 11) ? $mon+1 : 0;
print $cm, $monfolders[$cm],"\n" if $debug;
print_tickle(".".$monfolders[$cm],"Ticklers for ".$abbr[$cm]);
#
# if Friday, move any weekend ticklers into the inbox
if ($wday == 6) {
my $wefolder = $mgr->open($TODO.".weekend",access=>'rw') or die "Cannot open $@";
my $nrmsgs = $wefolder->messages;
if ($nrmsgs) {
$mgr->copyMessage($MAIL,$wefolder->messages) or die "Cannot copy messages $@";
}
$wefolder->close or die 'Cannot close '.$monfolder->name;
}
#
# If the first of the month, move any monthly ticklers into the inbox.
if ($mday == 1) {
my $monfolder = $mgr->open($TODO.".m".sprintf("%02d",$mon+1)."_".$abbr[$mon],access=>'rw') or die "Cannot open $@";
my $nrmsgs = $monfolder->messages;
if ($nrmsgs) {
$mgr->copyMessage($MAIL,$monfolder->messages) or die "Cannot copy messages $@";
}
$monfolder->close or die 'Cannot close '.$monfolder->name;
}
The output looks like this:
Ticklers for Oct 26, 2005 *MORE THAN ONE MONTH OLD* new links Current: Call for Vote -- GSEC Vice Chair Election I was wondering... Your Alltel Wireless Account online statement is now available ============================== 1 Days "Jim O'Brien" <>: GSEC AB Participation Follow Up 6 Days Electronic_Billing@dom.com: Your Dominion online statement is now available Electronic_Billing@dom.com: Your Dominion online statement is now available This Weekend: "Bank Online (R)": Your Online Statement Is Ready announce@highcriteria.com: Total Recorder Standard Edition 5.1 has been released Ticklers for Nov "A Friend" : Something to do Next Month


