1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #!/usr/bin/perl
use lib "$ENV{HOME}/lib/perl5";
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/lib/perl5";
use Getopt::Std;
use Net::IMAP::Simple::SSL;
use Email::Simple;
my %opts;
getopts('dlv', \%opts) or die "unknown option\n";
my $verbose = $opts{v};
my %conf;
#+
# get conf
#-
my $config = shift;
open my $conf_h, "<", $config or die "error $! opening config file ($config)\n";
while (<$conf_h>) {
chomp;
s/#.*$//;
next unless /^\s*(\S+)\s*(.*)$/;
$conf{$1} = $2;
}
my $imap_host = $conf{host};
my $imap_user = $conf{user};
my $imap_pass = $conf{pass};
print STDERR "Connecting to host \"$imap_host\" ..." if $verbose;
my $imap = new Net::IMAP::Simple::SSL( $imap_host , use_ssl => 1) or die "FAILED, cant bind to $imap_host\n";
print STDERR "SUCCESS\n" if $verbose;
print STDERR "Login with user=\"$imap_user\" ..." if $verbose;
if (! $imap->login( $imap_user , $imap_pass ) ) {
print STDERR "FAILED\n" if $verbose;
die "Cant login to imap server, error: " . $imap->errstr() . "\n";
}
print STDERR "SUCCESS\n" if $verbose; |
Partager