Skip to content

Commit

Permalink
initial backbones
Browse files Browse the repository at this point in the history
  • Loading branch information
alexm committed Feb 13, 2011
0 parents commit 55c4f98
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
App-backimap-*
.build
10 changes: 10 additions & 0 deletions bin/backimap
@@ -0,0 +1,10 @@
#!perl

use strict;

require App::backimap;

my $app = App::backimap->new(@ARGV);
$app->run();

__END__
13 changes: 13 additions & 0 deletions dist.ini
@@ -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]
28 changes: 28 additions & 0 deletions lib/App/backimap.pm
@@ -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;
38 changes: 38 additions & 0 deletions lib/App/backimap/Utils.pm
@@ -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;
80 changes: 80 additions & 0 deletions t/utils/uri.t
@@ -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 );
}

0 comments on commit 55c4f98

Please sign in to comment.