summaryrefslogtreecommitdiff
path: root/lib/JWebmail/Plugin
diff options
context:
space:
mode:
Diffstat (limited to 'lib/JWebmail/Plugin')
-rw-r--r--lib/JWebmail/Plugin/Helper.pm19
-rw-r--r--lib/JWebmail/Plugin/I18N.pm1
-rw-r--r--lib/JWebmail/Plugin/I18N2.pm1
-rw-r--r--lib/JWebmail/Plugin/ServerSideSessionData.pm16
4 files changed, 23 insertions, 14 deletions
diff --git a/lib/JWebmail/Plugin/Helper.pm b/lib/JWebmail/Plugin/Helper.pm
index f24bdba..c454b9f 100644
--- a/lib/JWebmail/Plugin/Helper.pm
+++ b/lib/JWebmail/Plugin/Helper.pm
@@ -2,7 +2,7 @@ package JWebmail::Plugin::Helper;
use Mojo::Base 'Mojolicious::Plugin';
-use List::Util qw(min max);
+use List::Util qw(all min max);
use Mojo::Util qw(encode decode b64_encode b64_decode xml_escape);
use POSIX qw(floor round log ceil);
@@ -45,8 +45,7 @@ sub filter_empty_upload {
### template formatting functions
sub print_sizes10 {
- my $var = shift;
- if ($var == 0) { return '0 Byte'; }
+ my $var = shift || return '0 Byte';
my $i = floor(((log($var)/log(10))+1e-5) / 3);
my $expo = $i * 3;
@@ -64,8 +63,7 @@ sub print_sizes10 {
sub print_sizes2 {
- my $var = shift;
- if ($var == 0) { return '0 Byte'; }
+ my $var = shift || return '0 Byte';
my $i = floor(((log($var)/log(2))+1e-5) / 10);
my $expo = $i * 10;
@@ -85,7 +83,10 @@ sub print_sizes2 {
sub d { qr/([[:digit:]]{$_[0]})/ }
sub parse_iso_date {
- my @d = shift =~ m/@{[d(4).'-'.d(2).'-'.d(2).'T'.d(2).':'.d(2).':'.d(2).'Z']}/;
+ my @d = shift =~ m/@{[d(4).'-'.d(2).'-'.d(2).'T'.d(2).':'.d(2).':'.d(2)]}/;
+ if (!all { defined $_ } @d) {
+ # TODO
+ }
return {
year => $d[0],
month => $d[1],
@@ -124,8 +125,9 @@ our %MIME_Render_Subs = (
sub mime_render {
my ($c, $enc, $cont) = @_;
- my $renderer = $MIME_Render_Subs{$enc};
- return '' unless defined $renderer;
+ ($enc) = $enc =~ m"^(\w+/\w+);?";
+
+ my $renderer = $MIME_Render_Subs{$enc} // return '';
return $renderer->($c, $cont);
};
@@ -288,6 +290,7 @@ sub paginate {
sub register {
my ($self, $app, $conf) = @_;
+ $conf //= {};
if (ref $conf->{import} eq 'ARRAY' and my @import = @{ $conf->{import} }) {
no warnings 'experimental::smartmatch';
diff --git a/lib/JWebmail/Plugin/I18N.pm b/lib/JWebmail/Plugin/I18N.pm
index 32ac917..6d58932 100644
--- a/lib/JWebmail/Plugin/I18N.pm
+++ b/lib/JWebmail/Plugin/I18N.pm
@@ -14,6 +14,7 @@ has '_language_loaded' => sub { {} };
sub register {
my ($self, $app, $conf) = @_;
+ $conf //= {};
my $i18n_log = $app->log->context('[' . __PACKAGE__ . ']');
diff --git a/lib/JWebmail/Plugin/I18N2.pm b/lib/JWebmail/Plugin/I18N2.pm
index 4217c70..5084c97 100644
--- a/lib/JWebmail/Plugin/I18N2.pm
+++ b/lib/JWebmail/Plugin/I18N2.pm
@@ -40,6 +40,7 @@ has '_language_loaded' => sub { {} };
sub register {
my ($self, $app, $conf) = @_;
+ $conf //= {};
my $i18n_log = $app->log->context('[' . __PACKAGE__ . ']');
diff --git a/lib/JWebmail/Plugin/ServerSideSessionData.pm b/lib/JWebmail/Plugin/ServerSideSessionData.pm
index 274594f..d416c00 100644
--- a/lib/JWebmail/Plugin/ServerSideSessionData.pm
+++ b/lib/JWebmail/Plugin/ServerSideSessionData.pm
@@ -9,10 +9,12 @@ use Fcntl ':DEFAULT', ':seek';
use Time::HiRes 'sleep';
-use constant S_KEY => 's3d.key';
-use constant CLEANUP_FILE_NAME => 'cleanup';
-use constant LOCK_ITER => 5;
-use constant ADVANCE_ON_FAILURE => 10; # seconds to retry to acquire the lock
+use constant {
+ S_KEY => 's3d.key',
+ CLEANUP_FILE_NAME => 'cleanup',
+ LOCK_ITER => 5,
+ ADVANCE_ON_FAILURE => 10, # seconds to retry to acquire the lock
+};
has 'session_directory';
has 'expiration';
@@ -21,7 +23,7 @@ has 'cleanup_interval';
has 'next_cleanup' => 0;
-# read und potentially update file return bool
+# read and potentially update file return bool
# needs atomic lock file
# the file contains a single timestamp
sub _rw_cleanup_file {
@@ -33,7 +35,7 @@ sub _rw_cleanup_file {
my ($lock, $ctr, $rmlock);
until (sysopen($lock, $lock_name, O_WRONLY | O_CREAT | O_EXCL)) {
- die "unexpected error '$!'" unless $! eq 'File exists';
+ die "unexpected error '$!'" unless $! eq 'File exists'; # TODO: rework err check
if ($ctr > LOCK_ITER) {
open($lock, '<', $lock_name) or die "unexpected error '$!'";
my $pid = <$lock>;
@@ -125,6 +127,7 @@ sub s3d {
$data->{$key} = $val;
$file->spurt(encode_json $data, "\n");
+ return;
}
else { # get
return defined $key ? $data->{$key} : $data;
@@ -134,6 +137,7 @@ sub s3d {
sub register {
my ($self, $app, $conf) = @_;
+ $conf //= {};
$self->session_directory(Mojo::File->new($conf->{directory} || "/tmp/" . $app->moniker));
$self->expiration($conf->{expiration} || $app->sessions->default_expiration);