package JWebmail::Model::ReadMails::MockMaildir; use Mojo::Base 'JWebmail::Model::ReadMails::QMailAuthuser'; use Mojo::JSON 'decode_json'; use JWebmail::Config 'LOGIN_SCHEME'; if (LOGIN_SCHEME eq fc 'cram_md5') { require Digest::HMAC_MD5; Digest::HMAC_MD5->import('hmac_md5_hex'); } use constant { VALID_USER => 'mockmaildir@example.org', VALID_PW => '12345', }; sub new { my $cls = shift; my %args = @_ == 1 ? %$_[0] : @_; my $self = bless {%args}, ref $cls || $cls; return $self->next::method(); } sub verify_user { my $self = shift; my $auth = shift; my $passwd = $auth->{password}->show_password; if ($auth->{challenge}) { return $auth->{user} eq VALID_USER && $passwd eq hmac_md5_hex($auth->{challenge}, VALID_PW); } else { return $auth->{user} eq VALID_USER && $passwd eq VALID_PW; } } sub start_qmauth { my $self = shift; my ($auth, $mode, $args) = @_; my $mail_user = 'maildir'; my @exec = ($self->{prog}, $self->{mailbox_path}, $self->{virtual_user}, $mail_user, $mode, @$args); my $pid = open(my $reader, '-|', @exec) or die "failed to create subprocess: $!"; return $pid, $reader; } 1