Created
February 11, 2011 18:03
-
-
Save waffle2k/822755 to your computer and use it in GitHub Desktop.
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
#!/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