summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Model/ReadMails/MockJSON.pm
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2023-09-10 15:39:25 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2023-09-10 15:39:25 +0200
commit278b76fabf31abe8fc4fbe6ca1c0ad6af830fcb7 (patch)
treea3ca8baafd3c26b6d8df3840fe92f5e2f2dd0c34 /lib/JWebmail/Model/ReadMails/MockJSON.pm
parent84186e77461ddeb867fa2944dcbf45217b41b80e (diff)
added test pam to replace MockMaildir ReadMail implementation
Diffstat (limited to 'lib/JWebmail/Model/ReadMails/MockJSON.pm')
-rw-r--r--lib/JWebmail/Model/ReadMails/MockJSON.pm137
1 files changed, 0 insertions, 137 deletions
diff --git a/lib/JWebmail/Model/ReadMails/MockJSON.pm b/lib/JWebmail/Model/ReadMails/MockJSON.pm
deleted file mode 100644
index 70daf8f..0000000
--- a/lib/JWebmail/Model/ReadMails/MockJSON.pm
+++ /dev/null
@@ -1,137 +0,0 @@
-package JWebmail::Model::ReadMails::MockJSON;
-
-use v5.24;
-use warnings;
-use utf8;
-use autodie;
-
-use List::Util 'sum';
-use JSON::PP '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 Role::Tiny::With;
-
-use namespace::clean;
-
-use constant {
- VALID_USER => 'mockjson@example.org',
- VALID_PW => '12345',
-};
-
-with 'JWebmail::Model::ReadMails::Role';
-
-
-sub new { bless {%$_[1]}, shift }
-
-sub _read_json_file {
- my ($self, $file_name) = @_;
-
- open my $body_file, '<', $self->{mailbox_path} . '/' . $file_name;
- local $/;
- my $body = <$body_file>;
- close $body_file;
-
- return decode_json($body);
-}
-
-sub list_reply {
- my $self = shift;
- state $init = _read_json_file($self, 'msgs.json');
-}
-
-sub read_reply {
- my $self = shift;
- state $init = {
- 'SC-ORD-MAIL54526c63b751646618a793be3f8329cca@sc-ord-mail5' => _read_json_file($self, 'msg2.json'),
- 'example' => _read_json_file($self, 'msg.json'),
- };
-}
-
-
-sub verify_user {
- my $self = shift;
- my $auth = shift;
-
- if ($auth->{challenge}) {
- my $res = hmac_md5_hex($auth->{challenge}, VALID_PW);
- return $auth->{user} eq VALID_USER && $auth->{password} eq $res;
- }
- return $auth->{user} eq VALID_USER && $auth->{password} eq VALID_PW;
-}
-
-sub read_headers_for {
- my $self = shift;
- my $auth = shift;
- my %args = @_;
-
- my ($start, $end, $sort, $folder) = @args{qw(start end sort folder)};
-
- unless ($sort) {
- return [@{ $self->list_reply }[$start..$end]];
- }
- if ($folder eq 'test') {
- return [];
- }
- my $s = sub {
- my $sort_by = $sort;
- my $rev = $sort_by !~ m/^!/ ? 1 : -1;
- $sort_by =~ s/^!//;
- return (($a->{$sort_by}||$a->{head}{$sort_by}) cmp ($b->{$sort_by}||$b->{head}{$sort_by})) * $rev;
- };
- return [sort { &$s } @{ $self->list_reply }[$start..$end]];
-}
-
-sub count {
- my $self = shift;
- my $auth = shift;
- my $_folder = shift;
-
- return (
- sum(map {$_->{size}} @{ $self->list_reply }), # size
- scalar(@{ $self->list_reply }), # count
- 0, # new
- );
-}
-
-sub show {
- my $self = shift;
- my $auth = shift;
- my $mid = shift;
-
- my $mail = $self->read_reply->{$mid};
- if ($mail) {
- return $mail;
- }
- else {
- die 'unknown mail-id';
- }
-}
-
-sub folders { ['', qw(cur test devel debug)] }
-
-sub raw {
- my $self = shift;
- my ($auth, $folder, $mid, $path) = @_;
-
- ...
-}
-
-sub search { ... }
-sub move { ... }
-
-
-1
-
-__END__
-
-=head1 NAME
-
-Mock - Simple file based mock for the L<JWebmail::Model::ReadMails> module.
-
-=cut