summaryrefslogtreecommitdiff
path: root/lib/JWebmail
diff options
context:
space:
mode:
Diffstat (limited to 'lib/JWebmail')
-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
5 files changed, 33 insertions, 34 deletions
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});
}