| 1 | package Mail::Decency::ContentFilter::Core; | ||||||||||
| 2 | |||||||||||
| 3 | 6 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 6 | extends 'Mail::Decency::Core::Child'; | |||||||||
| 5 | |||||||||||
| 6 | 6 | ▶ | use version 0.74; our $VERSION = qv( "v0.1.4" ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Mail::Decency::ContentFilter::Core | ||||||||||
| 11 | |||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||
| 13 | |||||||||||
| 14 | Base class for all content filter | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | =head1 CLASS ATTRIBUTES | ||||||||||
| 18 | |||||||||||
| 19 | =head2 max_size : Int | ||||||||||
| 20 | |||||||||||
| 21 | Max size in bytes for an email to be checked. | ||||||||||
| 22 | |||||||||||
| 23 | =cut | ||||||||||
| 24 | |||||||||||
| 25 | 6 | has max_size => ( is => 'ro', isa => 'Int', default => 0 ); | |||||||||
| 26 | |||||||||||
| 27 | =head2 timeout : Int | ||||||||||
| 28 | |||||||||||
| 29 | Timeout for each policy module. | ||||||||||
| 30 | |||||||||||
| 31 | Default: 30 | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | 6 | has timeout => ( is => 'rw', isa => 'Int', default => 30 ); | |||||||||
| 36 | |||||||||||
| 37 | =head2 ArrayRef[Str] : Int | ||||||||||
| 38 | |||||||||||
| 39 | For easy module initialization, developers can set array of the config params. They will be set if they are defined. | ||||||||||
| 40 | |||||||||||
| 41 | # do this | ||||||||||
| 42 | has config_params => ( is => 'ro', isa => 'ArrayRef[Str]', default => sub { [ qw/ something / ] } ); | ||||||||||
| 43 | |||||||||||
| 44 | # an it will be initialized | ||||||||||
| 45 | $self->something( $self->config->{ something } ) | ||||||||||
| 46 | if defined $self->config->{ something }; | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | 6 | has config_params => ( is => 'ro', isa => 'ArrayRef[Str]', predicate => 'has_config_params' ); | |||||||||
| 51 | |||||||||||
| 52 | |||||||||||
| 53 | =head1 METHODS | ||||||||||
| 54 | |||||||||||
| 55 | =head2 init | ||||||||||
| 56 | |||||||||||
| 57 | =cut | ||||||||||
| 58 | |||||||||||
| 59 | 0 | ▶ | sub init { | ||||||||
|
Subroutine
init: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 60 | 0 | my ( $self ) = @_; | |||||||||
| 61 | |||||||||||
| 62 | # run pre-init phase | ||||||||||
| 63 | 0 | ▶ | $self->pre_init() if $self->can( 'pre_init' ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | |||||||||||
| 65 | # each filter might have a max size for files to be filtered | ||||||||||
| 66 | 0 | ▶ | if ( defined $self->config->{ max_size } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 0 | $self->max_size( $self->config->{ max_size } ); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | # set timeout | ||||||||||
| 71 | $self->timeout( $self->config->{ timeout } ) | ||||||||||
| 72 | 0 | ▶ | if defined $self->config->{ timeout }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | |||||||||||
| 74 | # having list of optional config params ? | ||||||||||
| 75 | 0 | ▶ | if ( $self->has_config_params ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | foreach my $attr( @{ $self->config_params } ) { | |||||||||
| 77 | $self->$attr( $self->config->{ $attr } ) | ||||||||||
| 78 | 0 | ▶ | if $self->config->{ $attr }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | |||||||||||
| 85 | =head2 session_data, file, file_size, from, to, mime | ||||||||||
| 86 | |||||||||||
| 87 | Convinient accessor to the server's session data | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||
| 90 | |||||||||||
| 91 | 0 | ▶ | sub session_data { | ||||||||
|
Subroutine
session_data: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 92 | 0 | return shift->server->session_data; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | sub file { | ||||||||
|
Subroutine
file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 96 | 0 | return shift->session_data->file; | |||||||||
| 97 | } | ||||||||||
| 98 | 0 | ▶ | sub file_size { | ||||||||
|
Subroutine
file_size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 99 | 0 | return shift->session_data->file_size; | |||||||||
| 100 | } | ||||||||||
| 101 | 0 | ▶ | sub from { | ||||||||
|
Subroutine
from: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 102 | 0 | return shift->session_data->from; | |||||||||
| 103 | } | ||||||||||
| 104 | 0 | ▶ | sub to { | ||||||||
|
Subroutine
to: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 105 | 0 | return shift->session_data->to; | |||||||||
| 106 | } | ||||||||||
| 107 | 0 | ▶ | sub mime { | ||||||||
|
Subroutine
mime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 108 | 0 | return shift->session_data->mime; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | =head2 write_mime | ||||||||||
| 112 | |||||||||||
| 113 | Write latest MIME data back to file | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||
| 116 | |||||||||||
| 117 | 0 | ▶ | sub write_mime { | ||||||||
|
Subroutine
write_mime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 118 | 0 | return shift->session_data->write_mime; | |||||||||
| 119 | } | ||||||||||
| 120 | |||||||||||
| 121 | =head1 AUTHOR | ||||||||||
| 122 | |||||||||||
| 123 | Ulrich Kautz <uk@fortrabbit.de> | ||||||||||
| 124 | |||||||||||
| 125 | =head1 COPYRIGHT | ||||||||||
| 126 | |||||||||||
| 127 | Copyright (c) 2010 the L</AUTHOR> as listed above | ||||||||||
| 128 | |||||||||||
| 129 | =head1 LICENCSE | ||||||||||
| 130 | |||||||||||
| 131 | This library is free software and may be distributed under the same terms as perl itself. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||
| 134 | |||||||||||
| 135 | 6 | 1; | |||||||||