diff options
Diffstat (limited to 'lib/JWebmail.pm')
-rw-r--r-- | lib/JWebmail.pm | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/lib/JWebmail.pm b/lib/JWebmail.pm index eb03167..e672903 100644 --- a/lib/JWebmail.pm +++ b/lib/JWebmail.pm @@ -43,8 +43,7 @@ sub startup { if (fc $self->config->{session}{secure} eq fc 's3d') { $self->plugin('ServerSideSessionData'); } - $self->plugin('Helper'); - $self->plugin('RenderMail'); + $self->plugin('Paginate'); my $i18n_route = $self->plugin('I18N2', $self->config('i18n')); $self->secrets( [$self->config('secret')] ) if $self->config('secret'); @@ -70,6 +69,9 @@ sub startup { $JWebmail::Model::WriteMails::Block_Writes = 1 if $self->mode eq 'development' && $self->config->{model}{write}{devel}{block_writes}; + $self->validator->add_check(mail_line => \&_mail_line); + $self->validator->add_filter(non_empty_ul => \&_filter_empty_upload); + $self->defaults(version => __PACKAGE__->VERSION); $self->sessions->cookie_name('jwebmail_session'); @@ -101,6 +103,38 @@ sub route { } +### filter and checks for mojo validator + +sub _mail_line { + my ($v, $name, $value, @args) = @_; + + my $mail_addr = qr/\w+\@\w+\.\w+/; + # my $unescaped_quote = qr/"(*nlb:\\)/; # greater perl version required + my $unescaped_quote = qr/"(?<!:\\)/; + + return $value !~ /^( + ( + ( + ( + $unescaped_quote.*?$unescaped_quote + ) | ( + [\w\s]* + ) + ) + \s*<$mail_addr> + ) | ( + $mail_addr + ))$ + /xn; +} + +sub _filter_empty_upload { + my ($v, $name, $value) = @_; + + return $value->filename ? $value : undef; +} + + 1 __END__ @@ -123,6 +157,26 @@ And use a server in reverse proxy configuration. Use the I<jwebmail.conf> file or for a specific I<$mode> the I<jwebmail.$mode.conf>. +=head1 VALIDATOR + +=head2 mail_line + +A check for validator used in mail headers for fields containing email addresses. + + $app->validator->add_check(mail_line => \&JWebmail::Plugin::Helper::mail_line); + + my $v = $c->validation; + $v->required('to', 'not_empty')->check('mail_line'); + +=head2 filter_empty_upload + +A filter for validator used to filter out empty uploads. + + $app->validator->add_filter(non_empty_ul => \&JWebmail::Plugin::Helper::filter_empty_upload); + + my $v = $c->validation; + $v->required('file_upload', 'non_empty_ul'); + =head1 AUTHORS Copyright (C) 2020-2022 Jannis M. Hoffmann L<jannis@fehcom.de> |