summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2020-11-12 23:20:30 +0100
committerJannis M. Hoffmann <jannis.hoffmann@rwth-aachen.de>2020-11-12 23:20:30 +0100
commitbf5554febae6f299c716b5a9582c6bfd6980b728 (patch)
tree8a1ef7206ea5affca689ce71edf31e3114440fe9 /lib
parent487629cca62c29719e44df2e68cf14d8b0cc2f3e (diff)
+ added some files that should belonged to the last commit
+ preparation for supporting more mime types
Diffstat (limited to 'lib')
-rw-r--r--lib/JWebmail.pm8
-rw-r--r--lib/JWebmail/Controller/Webmail.pm24
-rw-r--r--lib/JWebmail/Model/Driver/Mock.pm6
-rw-r--r--lib/JWebmail/Model/WriteMails.pm3
-rw-r--r--lib/JWebmail/Plugin/I18N.pm2
-rw-r--r--lib/JWebmail/Plugin/I18N2.pm32
6 files changed, 37 insertions, 38 deletions
diff --git a/lib/JWebmail.pm b/lib/JWebmail.pm
index 7275891..dc68bd2 100644
--- a/lib/JWebmail.pm
+++ b/lib/JWebmail.pm
@@ -1,4 +1,4 @@
-package JWebmail v1.0.0;
+package JWebmail v1.1.0;
use Mojo::Base 'Mojolicious';
@@ -20,7 +20,7 @@ sub startup {
$self->plugin('INIConfig');
$self->plugin('ServerSideSessionData');
$self->plugin('Helper');
- $self->plugin('I18N', $self->config('i18n') // {});
+ my $i18n_route = $self->plugin('I18N2', $self->config('i18n') // {});
$self->secrets( [$self->config('secret')] ) if $self->config('secret');
delete $self->config->{secret};
@@ -42,7 +42,7 @@ sub startup {
# add helper and stash values
$self->defaults(version => __PACKAGE__->VERSION);
- $self->route();
+ $self->route($i18n_route);
}
@@ -105,4 +105,4 @@ See the CREDITS file for project contributors.
This module is licensed under the terms of the GPLv3 or any later version at your option.
Please take a look at the provided LICENSE file shipped with this module.
-=cut \ No newline at end of file
+=cut
diff --git a/lib/JWebmail/Controller/Webmail.pm b/lib/JWebmail/Controller/Webmail.pm
index 3ec93f1..5f8d986 100644
--- a/lib/JWebmail/Controller/Webmail.pm
+++ b/lib/JWebmail/Controller/Webmail.pm
@@ -2,7 +2,7 @@ package JWebmail::Controller::Webmail;
use Mojo::Base 'Mojolicious::Controller';
-use File::Type;
+use Mojolicious::Types;
use constant {
S_USER => 'user', # Key for user name in active session
@@ -219,7 +219,7 @@ sub sendmail {
$mail{bcc} = $v->optional('bcc', 'not_empty')->check('mail_line')->every_param;
$mail{reply} = $v->optional('back_to', 'not_empty')->check('mail_line')->param;
$mail{attach} = $v->optional('attach', 'non_empty_ul')->upload->param;
- $mail{attach_type} = File::Type->new()->mime_type($mail{attach}->asset->get_chunk(0, 512)) if $mail{attach};
+ $mail{attach_type} = Mojolicious::Types->new->file_type($mail{attach}->filename) if $mail{attach};
$mail{from} = $self->session(S_USER);
if ($v->has_error) {
@@ -292,14 +292,20 @@ sub raw {
my $mail = $self->users->show($auth, $mid);
- if ($self->param('body')//'' eq 'html') {
- if ($mail->{content_type} eq 'text/html') {
- $self->render(text => $mail->{body}) ;
- }
- elsif ($mail->{content_type} eq 'multipart/alternative') {
- my ($content) = grep {$_->{type} eq 'text/html'} @{ $mail->{body} };
+ my $v = $self->validation;
+ $v->optional('body')->like(qr/\w+/);
+ if ($v->has_error) {
+ return;
+ }
+
+ if (my $type = $self->param('body')) {
+ if ($mail->{content_type} =~ '^multipart/') {
+ my ($content) = grep {$_->{type} =~ $type} @{ $mail->{body} };
$self->render(text => $content->{val});
}
+ elsif ($mail->{content_type} =~ $type) {
+ $self->render(text => $mail->{body}) ;
+ }
else {
$self->res->code(404);
}
@@ -383,4 +389,4 @@ Displays the mail raw, ready to be downloaded.
Mojolicious and File::Type
-=cut \ No newline at end of file
+=cut
diff --git a/lib/JWebmail/Model/Driver/Mock.pm b/lib/JWebmail/Model/Driver/Mock.pm
index eb8c0d0..b2da1be 100644
--- a/lib/JWebmail/Model/Driver/Mock.pm
+++ b/lib/JWebmail/Model/Driver/Mock.pm
@@ -22,7 +22,9 @@ use constant {
sub _read_json_file {
my ($file_name) = @_;
- open(my $body_file, '<', $file_name);
+ use constant PREFIX => 't/private/';
+
+ open(my $body_file, '<', PREFIX . $file_name);
local $/;
my $body = <$body_file>;
close $body_file;
@@ -99,4 +101,4 @@ __END__
Mock - Simple file based mock for the L<JWebmail::Model::ReadMails> module.
-=cut \ No newline at end of file
+=cut
diff --git a/lib/JWebmail/Model/WriteMails.pm b/lib/JWebmail/Model/WriteMails.pm
index 5df5379..1807a72 100644
--- a/lib/JWebmail/Model/WriteMails.pm
+++ b/lib/JWebmail/Model/WriteMails.pm
@@ -6,7 +6,6 @@ use utf8;
use Exporter 'import';
our @EXPORT_OK = qw(sendmail);
-use Data::Dumper;
use Email::MIME;
@@ -140,4 +139,4 @@ Optinal attachment.
The mime type of the attachment.
-=cut \ No newline at end of file
+=cut
diff --git a/lib/JWebmail/Plugin/I18N.pm b/lib/JWebmail/Plugin/I18N.pm
index a554ff7..32ac917 100644
--- a/lib/JWebmail/Plugin/I18N.pm
+++ b/lib/JWebmail/Plugin/I18N.pm
@@ -6,6 +6,8 @@ use Mojolicious::Controller;
use Mojo::File;
use Mojo::Util 'monkey_patch';
+use Config::Tiny;
+
has '_language_loaded' => sub { {} };
diff --git a/lib/JWebmail/Plugin/I18N2.pm b/lib/JWebmail/Plugin/I18N2.pm
index 84d4af3..4217c70 100644
--- a/lib/JWebmail/Plugin/I18N2.pm
+++ b/lib/JWebmail/Plugin/I18N2.pm
@@ -6,6 +6,8 @@ use Mojolicious::Controller;
use Mojo::File;
use Mojo::Util 'monkey_patch';
+use Config::Tiny;
+
package JWebmail::Plugin::I18N2::Match {
use Mojo::Base 'Mojolicious::Routes::Match';
@@ -83,35 +85,23 @@ sub register {
};
$app->helper( l => sub { my $c = shift; $i18n->($c->stash->{lang}, shift) } );
+ # modify incoming url
$app->hook(before_dispatch => sub {
my $c = shift;
unshift @{ $c->req->url->path->parts }, ''
unless $self->_language_loaded->{$c->req->url->path->parts->[0] || ''};
});
- #$app->hook(before_dispatch => sub { my $c = shift; $c->match(JWebmail::Plugin::I18N2::Match->new(root => $c->app->routes, _i18n2_stash => $c->stash)); });
-
- # patch url_for
- my $mojo_url_for = Mojolicious::Controller->can('url_for');
- my $i18n_url_for = sub {
+ # modify generated url
+ $app->hook(before_dispatch => sub {
my $c = shift;
- if (ref $_[0] eq 'HASH') {
- $_[0]->{lang} ||= $c->stash('lang');
- }
- elsif (ref $_[1] eq 'HASH') {
- $_[1]->{lang} ||= $c->stash('lang');
- }
- elsif (@_) {
- push @_, lang => $c->stash('lang');
- }
- else {
- @_ = {lang => $c->stash('lang')};
- }
- return $mojo_url_for->($c, @_);
- };
- monkey_patch 'Mojolicious::Controller', url_for => $i18n_url_for;
+ $c->match(JWebmail::Plugin::I18N2::Match->new(
+ root => $c->app->routes,
+ _i18n2_stash => $c->stash,
+ ));
+ });
- return $app->routes->any('/:lang' => {lang => 'en'});
+ return $app->routes->any('/:lang' => {lang => $defaultLang});
}