| 1 | package Mail::Decency::Core::SessionItem::Policy; | ||||||||||
| 2 | |||||||||||
| 3 | 11 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 11 | extends qw/ | |||||||||
| 5 | Mail::Decency::Core::SessionItem | ||||||||||
| 6 | /; | ||||||||||
| 7 | |||||||||||
| 8 | 11 | ▶ | use version 0.74; our $VERSION = qv( "v0.1.4" ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 11 | ▶ | use MIME::QuotedPrint; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | Mail::Decency::Core::SessionItem | ||||||||||
| 15 | |||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||
| 17 | |||||||||||
| 18 | Represents an session item for either policy or content filter. | ||||||||||
| 19 | Base class, don't instantiate! | ||||||||||
| 20 | |||||||||||
| 21 | =head1 CLASS ATTRIBUTES | ||||||||||
| 22 | |||||||||||
| 23 | =head2 response | ||||||||||
| 24 | |||||||||||
| 25 | The current final response .. defaults to "DUNNO" | ||||||||||
| 26 | |||||||||||
| 27 | =cut | ||||||||||
| 28 | |||||||||||
| 29 | 11 | has response => ( is => 'rw', isa => "Str", default => "DUNNO" ); | |||||||||
| 30 | |||||||||||
| 31 | =head2 message | ||||||||||
| 32 | |||||||||||
| 33 | The message for the response line as ArrayRef | ||||||||||
| 34 | |||||||||||
| 35 | =cut | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | has message => ( is => 'rw', isa => "ArrayRef[Str]", default => sub { [] } ); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 38 | |||||||||||
| 39 | =head2 sign_key | ||||||||||
| 40 | |||||||||||
| 41 | Instance of L<Crypt::OpenSSL::RSA> representing the forward sign key | ||||||||||
| 42 | |||||||||||
| 43 | =cut | ||||||||||
| 44 | |||||||||||
| 45 | 11 | has sign_key => ( is => 'rw', isa => 'Crypt::OpenSSL::RSA', predicate => 'can_sign' ); | |||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | =head1 METHODS | ||||||||||
| 49 | |||||||||||
| 50 | =head2 for_cache | ||||||||||
| 51 | |||||||||||
| 52 | Returns hashref which can be cached | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub for_cache { | ||||||||
|
Subroutine
for_cache: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | 0 | my ( $self ) = @_; | |||||||||
| 58 | |||||||||||
| 59 | return { | ||||||||||
| 60 | 0 | spam_score => $self->spam_score, | |||||||||
| 61 | spam_details => $self->spam_details, | ||||||||||
| 62 | flags => $self->flags, | ||||||||||
| 63 | message => $self->message, | ||||||||||
| 64 | }; | ||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | =head2 update_from_cache | ||||||||||
| 68 | |||||||||||
| 69 | Updates current session from cached session | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||
| 73 | 0 | ▶ | sub update_from_cache { | ||||||||
|
Subroutine
update_from_cache: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 74 | 0 | my ( $self, $hash_ref ) = @_; | |||||||||
| 75 | |||||||||||
| 76 | $self->spam_score( $self->spam_score + $hash_ref->{ spam_score } ) | ||||||||||
| 77 | 0 | ▶ | if $hash_ref->{ spam_score }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | |||||||||||
| 79 | 0 | push @{ $self->spam_details }, @{ $hash_ref->{ spam_details } } | |||||||||
| 80 | 0 | ▶ | if $hash_ref->{ spam_details }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | |||||||||||
| 82 | 0 | push @{ $self->spam_details }, @{ $hash_ref->{ message } } | |||||||||
| 83 | 0 | ▶ | if $hash_ref->{ message }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | if ( $hash_ref->{ flags } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | $self->set_flag( $_ ) for keys %{ $hash_ref->{ flags } }; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 0 | return; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | =head2 generate_instance_header | ||||||||||
| 93 | |||||||||||
| 94 | Returns the instance header.. if forwarding should be forwarded and has sign key, it will be signed | ||||||||||
| 95 | |||||||||||
| 96 | =cut | ||||||||||
| 97 | |||||||||||
| 98 | 0 | ▶ | sub generate_instance_header { | ||||||||
|
Subroutine
generate_instance_header: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 99 | 0 | my ( $self, $forward_scoring ) = @_; | |||||||||
| 100 | |||||||||||
| 101 | 0 | my $sign_error; | |||||||||
| 102 | |||||||||||
| 103 | # shall we forward scoring ? | ||||||||||
| 104 | 0 | my $add = ""; | |||||||||
| 105 | 0 | ▶ | if ( $forward_scoring ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 0 | my @add = (); | |||||||||
| 107 | |||||||||||
| 108 | # 0: weight | ||||||||||
| 109 | 0 | push @add, $self->spam_score; | |||||||||
| 110 | |||||||||||
| 111 | # 1: timestap | ||||||||||
| 112 | 0 | push @add, time(); | |||||||||
| 113 | |||||||||||
| 114 | # 2: states, sep by "," | ||||||||||
| 115 | 0 | push @add, join( ",", sort keys %{ $self->flags } ); | |||||||||
| 116 | |||||||||||
| 117 | # 3-n: details sep by | | ||||||||||
| 118 | 0 | push @add, join( "|", @{ $self->spam_details } ); | |||||||||
| 119 | |||||||||||
| 120 | # signing | ||||||||||
| 121 | # sign all values added before with key | ||||||||||
| 122 | 0 | ▶ | if ( $self->can_sign ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 123 | 0 | my $signed_header = "unsigned"; | |||||||||
| 124 | |||||||||||
| 125 | # catch error, don't interrupt the whole process | ||||||||||
| 126 | 0 | eval { | |||||||||
| 127 | 0 | $signed_header = unpack( "H*", | |||||||||
| 128 | $self->sign_key->sign( join( "|", $self->id, @add ) ) ); | ||||||||||
| 129 | }; | ||||||||||
| 130 | 0 | $sign_error = $@; | |||||||||
| 131 | 0 | unshift @add, $signed_header; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | # not signed | ||||||||||
| 135 | else { | ||||||||||
| 136 | 0 | unshift @add, 'unsigned'; | |||||||||
| 137 | } | ||||||||||
| 138 | |||||||||||
| 139 | 0 | $add = "|". join( "|", @add ); | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | #join( CRLF. "\t", split( /\n/, $header ) | ||||||||||
| 143 | |||||||||||
| 144 | #return ( encode_qp( $self->id. $add ), $sign_error ); | ||||||||||
| 145 | 0 | return ( $self->id. $add, $sign_error ); | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | |||||||||||
| 149 | =head2 cleanup | ||||||||||
| 150 | |||||||||||
| 151 | Called at the very end of the session | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||
| 154 | |||||||||||
| 155 | 0 | ▶ | sub cleanup { | ||||||||
|
Subroutine
cleanup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 156 | 0 | my ( $self ) = @_; | |||||||||
| 157 | 0 | $self->unset; | |||||||||
| 158 | 0 | return ; | |||||||||
| 159 | } | ||||||||||
| 160 | |||||||||||
| 161 | =head1 AUTHOR | ||||||||||
| 162 | |||||||||||
| 163 | Ulrich Kautz <uk@fortrabbit.de> | ||||||||||
| 164 | |||||||||||
| 165 | =head1 COPYRIGHT | ||||||||||
| 166 | |||||||||||
| 167 | Copyright (c) 2010 the L</AUTHOR> as listed above | ||||||||||
| 168 | |||||||||||
| 169 | =head1 LICENCSE | ||||||||||
| 170 | |||||||||||
| 171 | This library is free software and may be distributed under the same terms as perl itself. | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | |||||||||||
| 176 | 11 | 1; | |||||||||