Show imap.pl syntax highlighted
#!/usr/bin/perl
use lib '/home/tkay/src/duckmail/lib';
use warnings;
use strict;
use Data::Dumper;
use Net::IMAP;
use Carp;
sub show_args
{
print "show_args called with: " . Dumper(\@_);
}
sub fetch
{
my $this = shift;
my $arg = shift;
my $envelope;
my $from;
if(defined($arg->{Items}{envelope})) {
$envelope = $arg->{Items}{envelope};
$from = $envelope->from->[0];
print "Message " . $envelope->message_id . " From " . $from->as_string . " about " . $envelope->subject . "\n";
} else {
show_args($this, $arg, @_);
}
}
print "Password: ";
`stty -echo`;
my $password = <STDIN>;
chomp $password;
`stty echo`;
print "\n";
my $c;
$c = new Net::IMAP('tick.uoregon.edu');
$c->set_untagged_callback("fetch", \&show_args);
#$c->set_untagged_callback("exists", \&show_args);
#$c->set_untagged_callback("recent", \&show_args);
#$c->set_untagged_callback("flags", \&show_args);
#$c->set_untagged_callback("status", \&show_args);
#$c->set_untagged_callback("ok", \&show_args);
#$c->set_untagged_callback("lsub", \&show_args);
$c->login('dummy1', $password) or croak "Could not log in";
$c->select('inbox') or croak "Select failed";
$c->fetch('1', 'uid', 'envelope', 'body.peek[text]<0.80>', 'flags');
$c->logout;
See more files for this project here