From e1bafc13858b5c72a7584c52d3d9d6d597d39e6b Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Tue, 31 Aug 2021 20:23:03 +0200 Subject: restructured ipc format --- lib/JWebmail/Model/Driver/MockJSON.pm | 5 +- lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm | 76 ++++++++++++---------- .../Model/Driver/QMailAuthuser/schema.json | 54 ++++++++------- 3 files changed, 72 insertions(+), 63 deletions(-) (limited to 'lib/JWebmail/Model/Driver') diff --git a/lib/JWebmail/Model/Driver/MockJSON.pm b/lib/JWebmail/Model/Driver/MockJSON.pm index aafc74d..258246d 100644 --- a/lib/JWebmail/Model/Driver/MockJSON.pm +++ b/lib/JWebmail/Model/Driver/MockJSON.pm @@ -62,9 +62,8 @@ sub communicate { my $s = sub { my $sort_by = $args{args}->[LIST_SORT]; my $rev = $sort_by !~ m/^![[:lower:]]+/ ? 1 : -1; - $sort_by =~ s/!//; - $sort_by = "date_received" if $sort_by eq "date"; - return ($a->{$sort_by} cmp $b->{$sort_by}) * $rev; + $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 }[$args{args}->[LIST_START]..$args{args}->[LIST_END]]], 0); } diff --git a/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm b/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm index 6639ad9..a59e265 100755 --- a/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm +++ b/lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm @@ -12,7 +12,7 @@ use Carp; use List::Util 'min'; use Encode v2.88 'decode'; -use open IO => ':encoding(UTF-8)', ':std'; +#use open IO => ':encoding(UTF-8)', ':std'; no warnings 'experimental::smartmatch'; use Mail::Box::Manager; @@ -22,9 +22,9 @@ use constant ROOT_MAILDIR => '.'; sub main { my ($maildir) = shift(@ARGV) =~ m/(.*)/; - my ($su) = shift(@ARGV) =~ m/(.*)/; - my ($user) = shift(@ARGV) =~ m/([[:alpha:]]+)/; - my $mode = shift @ARGV; _ok($mode =~ m/([[:alpha:]-]{1,20})/); + my ($su) = shift(@ARGV) =~ m/(.*)/; + my ($user) = shift(@ARGV) =~ m/([[:alpha:]]+)/; + my $mode = shift @ARGV; _ok($mode =~ m/([[:alpha:]-]{1,20})/); my @args = @ARGV; delete $ENV{PATH}; @@ -57,7 +57,7 @@ sub main { }; $folder->close; - print encode_json $reply; + print(encode_json $reply); if (ref $reply eq 'HASH' && $reply->{error}) { exit 3; } @@ -115,16 +115,18 @@ sub list { for my $msg (@msgs) { my $msg2 = { - subject => decode('MIME-Header', $msg->subject), - from => _addresses($msg->from), - to => _addresses($msg->to), - cc => _addresses($msg->cc), - bcc => _addresses($msg->bcc), - date_received => _iso8601_utc($msg->timestamp), - size => $msg->size, - content_type => ''. $msg->contentType, - mid => $msg->messageId, - new => $msg->label('seen'), + mid => $msg->messageId, + size => $msg->size, + new => $msg->label('seen'), + head => { + 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), + content_type => ''.$msg->contentType, + }, }; push @msgs2, $msg2; } @@ -165,19 +167,21 @@ sub _addresses { sub read_mail { my ($folder, $mid) = @_; - + my $msg = $folder->find($mid); return {error => 'no such message', mid => $mid} unless $msg; return { - subject => decode('MIME-Header', $msg->subject), - from => _addresses($msg->from), - to => _addresses($msg->to), - cc => _addresses($msg->cc), - bcc => _addresses($msg->bcc), - date_received => _iso8601_utc($msg->timestamp), - size => $msg->size, - content_type => ''. $msg->contentType, - body => do { + size => $msg->size, + head => { + 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), + content_type => ''. $msg->contentType, + }, + body => do { if ($msg->isMultipart) { [map {{type => ''. $_->contentType, val => '' . $_->decoded}} $msg->body->parts] } @@ -200,21 +204,23 @@ sub search { return scalar(grep { $_->decoded =~ /$search_pattern/ || (decode('MIME-Header', $_->subject)) =~ /$search_pattern/ } $m->body->parts) if $m->isMultipart; - $m->body->decoded =~ /$search_pattern/ ||(decode('MIME-Header', $m->subject)) =~ /$search_pattern/; + $m->body->decoded =~ /$search_pattern/ || (decode('MIME-Header', $m->subject)) =~ /$search_pattern/; }); my @msgs2; for my $msg (@msgs) { my $msg2 = { - subject => decode('MIME-Header', $msg->subject), - from => _addresses($msg->from), - to => _addresses($msg->to), - cc => _addresses($msg->cc), - bcc => _addresses($msg->bcc), - date_received => _iso8601_utc($msg->timestamp), - size => $msg->size, - content_type => ''. $msg->contentType, - mid => $msg->messageId, + size => $msg->size, + mid => $msg->messageId, + head => { + 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), + content_type => ''. $msg->contentType, + }, }; push @msgs2, $msg2; } diff --git a/lib/JWebmail/Model/Driver/QMailAuthuser/schema.json b/lib/JWebmail/Model/Driver/QMailAuthuser/schema.json index 5d5247a..b63a5eb 100644 --- a/lib/JWebmail/Model/Driver/QMailAuthuser/schema.json +++ b/lib/JWebmail/Model/Driver/QMailAuthuser/schema.json @@ -33,47 +33,51 @@ "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"}, + "date": {"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"] + "required": ["date", "from"] }, - "list": { + "head_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"} - } - } + "mail_body": { + "anyOf": [ + {"type": "string"}, + { + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "head": {"$ref": "#/definitions/mail_head"}, + "body": {"$ref": "#/definitions/mail_body"} } - ] + } + }, + { + "ref": "#/definitions/mail" } + ] + }, + "mail": { + "type": "object", + "properties": { + "new": {"type": "boolean"}, + "mid": {"type": "string"}, + "size": {"type": "integer", "minimum": 0}, + "head": {"$ref": "#/definitions/mail_head"}, + "body": {"$ref": "#/definitions/mail_body"} }, - "required": ["body"] + "required": ["mid"] } } } -- cgit v1.2.3