Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created February 11, 2011 18:03
Show Gist options
  • Save waffle2k/822755 to your computer and use it in GitHub Desktop.
Save waffle2k/822755 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use POE::Component::DirWatch::Object;
our %seen;
sub extractContents {
my $filename = shift;
print "Opening: $filename\n";
my ( $from, $subject ) = ( undef, undef );
open FD, "<$filename";
while ( <FD> ) {
chomp;
if ( /^Subject:\s*(.*)/ ) {
$subject = $_;
}
if ( /^From:/ ) {
$from = $_;
}
return [ $from, $subject ]
if ( $from && $subject );
} ## end while ( <FD> )
return [ undef, undef ];
} ## end sub extractContents
#$watcher is a PoCo::DW:Object
my $watcher = POE::Component::DirWatch::Object->new(
alias => 'dirwatch',
directory => '/home/pblair/Test/INBOX/new/',
filter => sub { -f $_[1] },
callback => sub {
my $filename = shift;
my $fullpath = shift;
unless ( $seen{$filename} ) {
my $x = extractContents( $fullpath );
print "Sending notification\n";
`notify-send \'$x->[0]\' \'$x->[1]\'`;
}
$seen{$filename}++;
},
# OR
interval => 1, );
POE::Kernel->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment