File: slurp_fetchmail.pm

package info (click to toggle)
libnet-imap-simple-perl 1.2211-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 372 kB
  • sloc: perl: 1,574; makefile: 4
file content (37 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (5)
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

package slurp_fetchmail;

use strict;
use warnings;
use Carp;
use File::Slurp qw(slurp);
use Net::IMAP::Simple;
use File::Basename;

sub login {
    my $class = shift;
    my $fetchmailrc = slurp("$ENV{HOME}/.fetchmailrc");
    my ($server)    = $fetchmailrc =~ m/server\s+(.+)/m;
    my ($user)      = $fetchmailrc =~ m/user\s+(.+)/m;
    my ($pass)      = $fetchmailrc =~ m/pass\s+(.+)/m;

    croak "server, user and pass must be in the $ENV{HOME}/.fetchmailrc for this to work"
        unless $server and $user and $pass;

    if( exists $ENV{DEBUG} ) {
        if( $ENV{DEBUG} eq "1" ) {
            $ENV{DEBUG} = basename($0);
            $ENV{DEBUG} .= ".log";
        }
    }

    my $imap = Net::IMAP::Simple->new($server,
        ($ENV{DEBUG} ? (debug=>do { open my $x, ">>", $ENV{DEBUG} or die $!; $x}) : ()),
        @_) or croak "connect failed: $Net::IMAP::Simple::errstr";

    $imap->login($user=>$pass) or croak "login failed: " . $imap->errstr;

    return $imap;
}

"True";