From 2388747fbf954de990862a6c01713d50823e8725 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Tue, 24 Aug 2021 11:10:39 +0200 Subject: overhauled testing --- lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm | 25 +++---- .../Model/Driver/QMailAuthuser/schema.json | 79 ++++++++++++++++++++++ 2 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 lib/JWebmail/Model/Driver/QMailAuthuser/schema.json (limited to 'lib/JWebmail/Model/Driver/QMailAuthuser') diff --git a/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm b/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm index 30ac4e9..5c31d58 100755 --- a/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm +++ b/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm @@ -1,3 +1,4 @@ +#!/usr/bin/env perl package JWebmail::Model::Driver::QMailAuthuser::Extract; use v5.18; @@ -8,16 +9,15 @@ use utf8; use POSIX (); use JSON::PP; use Carp; -use Encode v2.88 qw(decode); +use List::Util 'min'; +use Encode v2.88 'decode'; use open IO => ':encoding(UTF-8)', ':std'; no warnings 'experimental::smartmatch'; use Mail::Box::Manager; -use constant { - ROOT_MAILDIR => '.', -}; +use constant ROOT_MAILDIR => '.'; sub main { @@ -109,19 +109,18 @@ sub list { my $sref = _sort_mails($sortby); my @msgs = $f->messages; @msgs = sort { &$sref } @msgs; - @msgs = @msgs[$start..$end]; + @msgs = @msgs[$start..min($#msgs, $end)]; my @msgs2; for my $msg (@msgs) { my $msg2 = { - #subject => scalar decode_mimewords($msg->subject), subject => decode('MIME-Header', $msg->subject), from => _addresses($msg->from), to => _addresses($msg->to), cc => _addresses($msg->cc), bcc => _addresses($msg->bcc), - date => _iso8601_utc($msg->timestamp), + date_received => _iso8601_utc($msg->timestamp), size => $msg->size, content_type => ''. $msg->contentType, mid => $msg->messageId, @@ -175,7 +174,7 @@ sub read_mail { to => _addresses($msg->to), cc => _addresses($msg->cc), bcc => _addresses($msg->bcc), - date => _iso8601_utc($msg->timestamp), + date_received => _iso8601_utc($msg->timestamp), size => $msg->size, content_type => ''. $msg->contentType, body => do { @@ -191,9 +190,7 @@ sub read_mail { sub search { - my $f = shift; - my $search_pattern = shift; - my $folder = shift; + my ($f, $search_pattern, $folder) = @_; $folder = ".$folder"; $f = $f->openSubFolder($folder) if $folder ne ROOT_MAILDIR; @@ -214,7 +211,7 @@ sub search { to => _addresses($msg->to), cc => _addresses($msg->cc), bcc => _addresses($msg->bcc), - date => _iso8601_utc($msg->timestamp), + date_received => _iso8601_utc($msg->timestamp), size => $msg->size, content_type => ''. $msg->contentType, mid => $msg->messageId, @@ -229,7 +226,7 @@ sub search { sub folders { my $f = shift; - return [grep { $_ =~ m/^\./ && $_ =~ s/\.// && 1 } $f->listSubFolders]; + return [grep { $_ =~ m/^\./ && $_ =~ s/\.// } $f->listSubFolders]; } @@ -290,4 +287,4 @@ Currently Mail::Box::Manager does all the hard work. L -=cut \ No newline at end of file +=cut diff --git a/lib/JWebmail/Model/Driver/QMailAuthuser/schema.json b/lib/JWebmail/Model/Driver/QMailAuthuser/schema.json new file mode 100644 index 0000000..5d5247a --- /dev/null +++ b/lib/JWebmail/Model/Driver/QMailAuthuser/schema.json @@ -0,0 +1,79 @@ +{ + "$schema": "http://json-schema.org/schema#", + "definitions": { + "count": { + "type": "object", + "properties": { + "new": {"type": "integer", "minimum": 0}, + "size": {"type": "integer", "minimum": 0}, + "count": {"type": "integer", "minimum": 0}, + "unread": {"type": "integer", "minimum": 0} + }, + "required": ["count"], + "additionalProperties": false + }, + "folders": { + "type": "array", + "items": { + "type": "string" + } + }, + "mail_addrs": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": {"type": "string"}, + "address": {"type": "string"} + }, + "required": ["address"] + }, + "minItems": 1 + }, + "mail_head": { + "type": "object", + "properties": { + "new": {"type": "boolean"}, + "mid": {"type": "string"}, + "content_type": {"type": "string"}, + "size": {"type": "integer", "minimum": 0}, + "date_send": {"type": "string"}, + "date_received": {"type": "string"}, + "cc": {"$ref": "#/definitions/mail_addrs"}, + "bcc": {"$ref": "#/definitions/mail_addrs"}, + "to": {"$ref": "#/definitions/mail_addrs"}, + "from": {"$ref": "#/definitions/mail_addrs"}, + "subject": {"type": "string"} + }, + "required": ["mid"] + }, + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/mail_head" + } + }, + "mail": { + "$ref": "#/definitions/mail_head", + "properties": { + "body": { + "anyOf": [ + {"type": "string"}, + { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "val": {"type": "string"}, + "type": {"type": "string"} + } + } + } + ] + } + }, + "required": ["body"] + } + } +} -- cgit v1.2.3