package JWebmail v1.2.0; use Mojo::Base Mojolicious; use JWebmail::Controller::Webmail; use JWebmail::Model::ReadMails::Role; use JWebmail::Model::ReadMails::QMailAuthuser; use JWebmail::Model::WriteMails; sub nest { } sub validateConf { my $self = shift; my $conf = $self->config; my $v = $self->validator->validation->input($conf); $v->optional('secret', 'not_empty'); $v->optional('i18n'); $v->required('session')->required('secure')->in(qw(none cram s3d)); $v->required('defaults')->required('scriptadmin')->like(qr/@/); my $dev = $v->optional('development'); $dev->optional('read_mock', 'not_empty'); $dev->optional('block_writes')->in(0, 1); for ($v->failed->@*) { say "reasons for $_: " , $v->error($_)->@*; } $v->is_valid; } sub startup { my $self = shift; $self->moniker('jwebmail'); my $mode = $self->mode; $self->log->path($self->home->child('log', "$mode.log")); # load plugins push @{$self->plugins->namespaces}, 'JWebmail::Plugin'; $self->plugin('INIConfig'); #die unless $self->validateConf; $self->plugin('ServerSideSessionData'); $self->plugin('Helper'); my $i18n_route = $self->plugin('I18N2', $self->config('i18n')); $self->secrets( [$self->config('secret')] ) if $self->config('secret'); delete $self->config->{secret}; # initialize models my $read_mails = do { if ($mode eq 'development') { my $cls = $self->config->{development}{read_mock}; eval "require $cls" || die "Issue for module $cls with: $@"; $cls->new; } else { JWebmail::Model::ReadMails::QMailAuthuser->new( logfile => $self->home->child('log', 'extract.log'), ); } }; die "given class @{[ ref $read_mails ]} does not ReadMails" unless $read_mails->DOES('JWebmail::Model::ReadMails::Role'); $self->helper(users => sub { $read_mails }); $self->helper(send_mail => sub { my ($c, $mail) = @_; JWebmail::Model::WriteMails::sendmail($mail) }); $JWebmail::Model::WriteMails::Block_Writes = 1 if $mode eq 'development'; $self->defaults(version => __PACKAGE__->VERSION); $self->route($i18n_route); } sub route { my $self = shift; my $r = shift || $self->routes; $r->get('/' => 'noaction')->to('Webmail#noaction'); $r->get('/about')->to('Webmail#about'); $r->post('/login')->to('Webmail#login'); $r->get('/logout')->to('Webmail#logout'); my $a = $r->under('/')->to('Webmail#auth'); $a->get('/home/*folder')->to('Webmail#displayheaders', folder => '')->name('displayheaders'); $a->get('/read/#id' => 'read')->to('Webmail#readmail'); $a->get('/write')->to('Webmail#writemail'); $a->post('/write' => 'send')-> to('Webmail#sendmail'); $a->post('/move')->to('Webmail#move'); } 1 __END__ =encoding utf-8 =head1 NAME JWebmail - Provides a web based e-mail client meant to be used with s/qmail. =head1 SYNOPSIS hypnotoad script/jwebmail And use a server in reverse proxy configuration. =head1 DESCRIPTION =head1 CONFIGURATION Use the I file or for a specific I<$mode> the I. =head1 AUTHORS Copyright (C) 2020-2022 Jannis M. Hoffmann L =head1 BASED ON IDEAS Copyright (C) 2001 Olivier Müller L (GPLv2+ project: oMail Webmail) Copyright (C) 2000 Ernie Miller (GPL project: Neomail) See the CREDITS file for project contributors. =head1 LICENSE This module is licensed under the terms of the GPLv3. Please take a look at the provided LICENSE file shipped with this module. =cut