From 8ee2d7149baa58ea225cb40e0f95030ee21f1081 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Mon, 13 Mar 2023 21:34:03 +0100 Subject: Split up Helper plugin and added Views instead --- lib/JWebmail.pm | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'lib/JWebmail.pm') 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/"(? + ) | ( + $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 file or for a specific I<$mode> the I. +=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 -- cgit v1.2.3