| 1 | package Mail::MtPolicyd::Plugin::ClearFields; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = '2.01'; # VERSION | |||||||||
| 7 | # ABSTRACT: mtpolicyd plugin to unset session variables | ||||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | 2 | extends 'Mail::MtPolicyd::Plugin'; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use Mail::MtPolicyd::Plugin::Result; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | has 'fields' => ( is => 'rw', isa => 'Maybe[Str]' ); | |||||||||
| 15 | 2 | has 'fields_prefix' => ( is => 'rw', isa => 'Maybe[Str]' ); | |||||||||
| 16 | |||||||||||
| 17 | sub clear_fields { | ||||||||||
| 18 | 1 | ▶ | my ( $self, $r ) = @_; | ||||||||
|
Subroutine
clear_fields: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 19 | 1 | my @fields = split(/\s*,\s*/, $self->fields); | |||||||||
| 20 | |||||||||||
| 21 | 1 | $self->log($r, 'clearing fields '.join(', ', @fields)); | |||||||||
| 22 | 1 | foreach my $field ( @fields ) { | |||||||||
| 23 | 1 | delete $r->session->{$field}; | |||||||||
| 24 | } | ||||||||||
| 25 | 1 | return; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | sub clear_fields_prefix { | ||||||||||
| 29 | 1 | ▶ | my ( $self, $r ) = @_; | ||||||||
|
Subroutine
clear_fields_prefix: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 30 | 1 | my @prefixes = split(/\s*,\s*/, $self->fields_prefix); | |||||||||
| 31 | |||||||||||
| 32 | 1 | $self->log($r, 'clearing fields with prefixes: '.join(', ', @prefixes)); | |||||||||
| 33 | 1 | foreach my $prefix ( @prefixes ) { | |||||||||
| 34 | 2 | foreach my $field ( keys %{$r->session} ) { | |||||||||
| 35 | 13 | ▶ | if( $field !~ /^\Q$prefix\E/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 8 | next; | |||||||||
| 37 | } | ||||||||||
| 38 | 5 | delete $r->session->{$field}; | |||||||||
| 39 | } | ||||||||||
| 40 | } | ||||||||||
| 41 | 1 | return; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub run { | ||||||||||
| 45 | 1 | ▶ | my ( $self, $r ) = @_; | ||||||||
|
Subroutine
run: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | 1 | ▶ | if( defined $self->fields) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 1 | $self->clear_fields( $r ); | |||||||||
| 49 | } | ||||||||||
| 50 | 1 | ▶ | if( defined $self->fields_prefix) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 1 | $self->clear_fields_prefix( $r ); | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 1 | return; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 58 | |||||||||||
| 59 | 2 | 1; | |||||||||
| 60 | |||||||||||
| 61 | __END__ | ||||||||||
| 62 | |||||||||||
| 63 | =pod | ||||||||||
| 64 | |||||||||||
| 65 | =encoding UTF-8 | ||||||||||
| 66 | |||||||||||
| 67 | =head1 NAME | ||||||||||
| 68 | |||||||||||
| 69 | Mail::MtPolicyd::Plugin::ClearFields - mtpolicyd plugin to unset session variables | ||||||||||
| 70 | |||||||||||
| 71 | =head1 VERSION | ||||||||||
| 72 | |||||||||||
| 73 | version 2.01 | ||||||||||
| 74 | |||||||||||
| 75 | =head1 DESCRIPTION | ||||||||||
| 76 | |||||||||||
| 77 | This plugin could be used to reset some session variables. | ||||||||||
| 78 | |||||||||||
| 79 | =head1 PARAMETERS | ||||||||||
| 80 | |||||||||||
| 81 | =over | ||||||||||
| 82 | |||||||||||
| 83 | =item fields (default: empty) | ||||||||||
| 84 | |||||||||||
| 85 | A comma separated list of session variables to unset. | ||||||||||
| 86 | |||||||||||
| 87 | =item fields_prefix (default: empty) | ||||||||||
| 88 | |||||||||||
| 89 | A comma separated list of prefixes. | ||||||||||
| 90 | All session variables with this prefixes will be unset. | ||||||||||
| 91 | |||||||||||
| 92 | =back | ||||||||||
| 93 | |||||||||||
| 94 | =head1 EXAMPLE | ||||||||||
| 95 | |||||||||||
| 96 | <Plugin cleanup> | ||||||||||
| 97 | module = "ClearFields" | ||||||||||
| 98 | fields = "spamhaus-rbl,spamhaus-dbl" | ||||||||||
| 99 | </Plugin> | ||||||||||
| 100 | |||||||||||
| 101 | Will remove both fields from the session. | ||||||||||
| 102 | |||||||||||
| 103 | <Plugin cleanup> | ||||||||||
| 104 | module = "ClearFields" | ||||||||||
| 105 | fields_prefix = "spamhaus-" | ||||||||||
| 106 | </Plugin> | ||||||||||
| 107 | |||||||||||
| 108 | Will also remove both fields and everything else starting with "spamhaus-" from the session. | ||||||||||
| 109 | |||||||||||
| 110 | =head1 AUTHOR | ||||||||||
| 111 | |||||||||||
| 112 | Markus Benning <ich@markusbenning.de> | ||||||||||
| 113 | |||||||||||
| 114 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 115 | |||||||||||
| 116 | This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. | ||||||||||
| 117 | |||||||||||
| 118 | This is free software, licensed under: | ||||||||||
| 119 | |||||||||||
| 120 | The GNU General Public License, Version 2, June 1991 | ||||||||||
| 121 | |||||||||||
| 122 | =cut | ||||||||||