diff options
Diffstat (limited to 'lib/JWebmail/Model/ReadMails/MockMaildir.pm')
-rw-r--r-- | lib/JWebmail/Model/ReadMails/MockMaildir.pm | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/JWebmail/Model/ReadMails/MockMaildir.pm b/lib/JWebmail/Model/ReadMails/MockMaildir.pm index 31e9618..d1746ec 100644 --- a/lib/JWebmail/Model/ReadMails/MockMaildir.pm +++ b/lib/JWebmail/Model/ReadMails/MockMaildir.pm @@ -1,36 +1,41 @@ package JWebmail::Model::ReadMails::MockMaildir; -use Mojo::Base -base; +use Mojo::Base JWebmail::Model::ReadMails::QMailAuthuser; use Mojo::JSON 'decode_json'; +use constant { + VALID_USER => 'me@mockmaildir.com', + VALID_PW => '12345', +}; -has user => sub { $ENV{USER} }; -has maildir => 't/'; + +has user => sub { $ENV{USER} }; +has maildir => 't/'; has extractor => 'perl'; our %EXTRACTORS = ( - perl => 'perl lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm', + perl => 'perl script/qmauth.pl', rust => 'extract/target/debug/jwebmail-extract', ); -use constant { - VALID_USER => 'me@mockmaildir.com', - VALID_PW => '12345', -}; -sub communicate { +sub verify_user { my $self = shift; - my %args = @_; + my $auth = shift; - if ($args{mode} eq 'auth') { - return ("", 0) if $args{user} eq VALID_USER && $args{password} eq VALID_PW; - return ("", 1); - } + return $auth->{user} eq VALID_USER && $auth->{password} eq VALID_PW; +} + +sub build_and_run { + my $self = shift; + my $auth = shift; + my $mode = shift; + my $args = shift; my $mail_user = 'maildir'; - my $exec = $EXTRACTORS{$self->extractor} . ' ' . join(' ', map { $_ =~ s/(['\\])/\\$1/g; "'$_'" } ($self->maildir, $self->user, $mail_user, $args{mode}, @{$args{args}})); + my $exec = $EXTRACTORS{$self->extractor} . ' ' . join(' ', map { $_ =~ s/(['\\])/\\$1/g; "'$_'" } ($self->maildir, $self->user, $mail_user, $mode, @$args)); my $pid = open(my $reader, '-|', $exec) or die 'failed to create subprocess'; @@ -49,9 +54,9 @@ sub communicate { $resp = {error => "qmail-authuser returned code: $rc"}; } - return ($resp, $rc); + die "error $resp" if $rc; + return $resp; } 1 - |