diff options
author | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2022-04-26 01:06:11 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2022-04-26 01:06:11 +0200 |
commit | affff46cea8dad31bb850ec27ba2a57f123e681b (patch) | |
tree | 8eca6f4b2c21ca0ea08f33c5ee104070fecee9db /lib/JWebmail/Model/ReadMails/MockMaildir.pm | |
parent | eae7431ea9ee9d87634b3938b5cf8b64ebdbfb5a (diff) |
adjusted QMailAuthuser to ReadMails Role
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 - |