forked from alexm/App-backimap
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 55c4f98
Showing
6 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
App-backimap-* | ||
.build |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!perl | ||
|
||
use strict; | ||
|
||
require App::backimap; | ||
|
||
my $app = App::backimap->new(@ARGV); | ||
$app->run(); | ||
|
||
__END__ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name = App-backimap | ||
author = Alex Muntada <alexm@cpan.org> | ||
license = Perl_5 | ||
copyright_holder = Alex Muntada | ||
copyright_year = 2011 | ||
|
||
version = 0.01 | ||
|
||
[@Git] | ||
|
||
[@Basic] | ||
|
||
[AutoPrereqs] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package App::backimap; | ||
# ABSTRACT: backups imap mail | ||
|
||
use Modern::Perl; | ||
|
||
use URI; | ||
use App::backimap::Utils qw( imap_uri_split ); | ||
use Data::Dump qw( dump ); | ||
|
||
sub new { | ||
my ( $class, @argv ) = @_; | ||
|
||
my %opt; | ||
$opt{args} = \@argv; | ||
|
||
return bless \%opt, $class; | ||
} | ||
|
||
sub run { | ||
my ($self) = @_; | ||
|
||
my ($str) = @{ $self->{args} }; | ||
|
||
my $uri = URI->new($str); | ||
dump imap_uri_split($uri); | ||
} | ||
|
||
1; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package App::backimap::Utils; | ||
# ABSTRACT: backimap utilities | ||
|
||
use Modern::Perl; | ||
|
||
use Exporter qw( import ); | ||
|
||
use URI::imap (); | ||
use URI::imaps (); | ||
|
||
our @EXPORT_OK = qw( imap_uri_split ); | ||
|
||
sub imap_uri_split { | ||
my ($uri) = @_; | ||
|
||
die "not an imap uri\n" | ||
unless ref $uri && | ||
( $uri->isa('URI::imap') || $uri->isa('URI::imaps') ); | ||
|
||
my ( $user, $password ) = split /:/, $uri->userinfo | ||
if defined $uri->userinfo; | ||
|
||
return { | ||
host => $uri->host, | ||
port => $uri->port, | ||
secure => $uri->secure, | ||
user => $user, | ||
password => $password, | ||
}; | ||
} | ||
|
||
# FIXME: URI::imaps does not override secure method with a true value | ||
# https://rt.cpan.org/Ticket/Display.html?id=65679 | ||
package URI::imaps; | ||
|
||
sub secure { 1 } | ||
|
||
1; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
use URI; | ||
use App::backimap::Utils qw( imap_uri_split ); | ||
|
||
my %test_case = ( | ||
'imap:' => { | ||
secure => 0, | ||
user => undef, | ||
password => undef, | ||
host => undef, | ||
port => 143, | ||
}, | ||
|
||
'imaps:' => { | ||
secure => 1, | ||
user => undef, | ||
password => undef, | ||
host => undef, | ||
port => 993, | ||
}, | ||
|
||
'imap://server.example.com' => { | ||
secure => 0, | ||
user => undef, | ||
password => undef, | ||
host => 'server.example.com', | ||
port => 143, | ||
}, | ||
|
||
'imaps://server.example.com' => { | ||
secure => 1, | ||
user => undef, | ||
password => undef, | ||
host => 'server.example.com', | ||
port => 993, | ||
}, | ||
|
||
'imap://user@example.com@server.example.com' => { | ||
secure => 0, | ||
user => 'user@example.com', | ||
password => undef, | ||
host => 'server.example.com', | ||
port => 143, | ||
}, | ||
|
||
'imaps://user@example.com@server.example.com' => { | ||
secure => 1, | ||
user => 'user@example.com', | ||
password => undef, | ||
host => 'server.example.com', | ||
port => 993, | ||
}, | ||
|
||
'imap://user@example.com:password@server.example.com' => { | ||
secure => 0, | ||
user => 'user@example.com', | ||
password => 'password', | ||
host => 'server.example.com', | ||
port => 143, | ||
}, | ||
|
||
'imaps://user@example.com:password@server.example.com' => { | ||
secure => 1, | ||
user => 'user@example.com', | ||
password => 'password', | ||
host => 'server.example.com', | ||
port => 993, | ||
}, | ||
); | ||
|
||
plan tests => scalar keys %test_case; | ||
for my $test (sort keys %test_case) { | ||
is_deeply( imap_uri_split( URI->new($test) ), $test_case{$test}, $test ); | ||
} |