diff options
author | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2021-08-31 20:23:03 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de> | 2021-08-31 20:23:03 +0200 |
commit | e1bafc13858b5c72a7584c52d3d9d6d597d39e6b (patch) | |
tree | b7135f6c08ab43a97ab2e5fce896b470461829bd /lib | |
parent | 1e1eabaac06721ee0d686d10a6effa9a3450a1ca (diff) |
restructured ipc format
Diffstat (limited to 'lib')
-rw-r--r-- | lib/JWebmail/Controller/Webmail.pm | 8 | ||||
-rw-r--r-- | lib/JWebmail/Model/Driver/MockJSON.pm | 5 | ||||
-rwxr-xr-x | lib/JWebmail/Model/Driver/QMailAuthuser/Extract.pm | 76 | ||||
-rw-r--r-- | lib/JWebmail/Model/Driver/QMailAuthuser/schema.json | 54 |
4 files changed, 76 insertions, 67 deletions
diff --git a/lib/JWebmail/Controller/Webmail.pm b/lib/JWebmail/Controller/Webmail.pm index f0f2efa..cd7b5c7 100644 --- a/lib/JWebmail/Controller/Webmail.pm +++ b/lib/JWebmail/Controller/Webmail.pm @@ -298,11 +298,11 @@ sub raw { } if (my $type = $self->param('body')) { - if ($mail->{content_type} =~ '^multipart/') { - my ($content) = grep {$_->{type} =~ $type} @{ $mail->{body} }; - $self->render(text => $content->{val}); + if ($mail->{head}{content_type} =~ '^multipart/') { + my ($content) = grep {$_->{head}{content_type} =~ $type} @{ $mail->{body} }; + $self->render(text => $content->{body}); } - elsif ($mail->{content_type} =~ $type) { + elsif ($mail->{head}{content_type} =~ $type) { $self->render(text => $mail->{body}) ; } else { 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"] } } } |