| 1 | package Mail::MtPolicyd::Plugin::AddScoreHeader; | ||||||||||
| 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 for adding the score as header to the mail | ||||||||||
| 8 | |||||||||||
| 9 | 2 | extends 'Mail::MtPolicyd::Plugin'; | |||||||||
| 10 | 2 | with 'Mail::MtPolicyd::Plugin::Role::Scoring'; | |||||||||
| 11 | 2 | with 'Mail::MtPolicyd::Plugin::Role::UserConfig' => { | |||||||||
| 12 | 'uc_attributes' => [ 'spam_score' ], | ||||||||||
| 13 | }; | ||||||||||
| 14 | |||||||||||
| 15 | 2 | ▶ | use Mail::MtPolicyd::Plugin::Result; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | 2 | has 'header_name' => ( | |||||||||
| 19 | is => 'ro', isa => 'Str', | ||||||||||
| 20 | default => 'X-MtScore', | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | 2 | has 'spam_score' => ( is => 'ro', isa => 'Num', default => '5' ); | |||||||||
| 24 | |||||||||||
| 25 | sub run { | ||||||||||
| 26 | 1 | ▶ | my ( $self, $r ) = @_; | ||||||||
|
Subroutine
run: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||
| 27 | 1 | my $score = $self->_get_score($r); | |||||||||
| 28 | 1 | my $spam_score = $self->get_uc($r->session, 'spam_score'); | |||||||||
| 29 | 1 | my $value; | |||||||||
| 30 | 1 | ▶ | if( ! defined $score ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | $self->log($r, 'score is undefined'); | |||||||||
| 32 | } | ||||||||||
| 33 | 1 | ▶ | if( $score >= $spam_score ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 1 | $value = 'YES '; | |||||||||
| 35 | } else { | ||||||||||
| 36 | 0 | $value = 'NO '; | |||||||||
| 37 | } | ||||||||||
| 38 | 1 | $value .= 'score='.$score; | |||||||||
| 39 | 1 | ▶ | if( my $details = $self->_get_score_detail($r) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1 | $value .= ' ['.$details.']'; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 1 | return Mail::MtPolicyd::Plugin::Result->new_header_once( | |||||||||
| 44 | $r->is_already_done('score-'.$self->score_field.'-tag'), | ||||||||||
| 45 | $self->header_name, $value ); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 49 | |||||||||||
| 50 | 2 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||
| 53 | |||||||||||
| 54 | =pod | ||||||||||
| 55 | |||||||||||
| 56 | =encoding UTF-8 | ||||||||||
| 57 | |||||||||||
| 58 | =head1 NAME | ||||||||||
| 59 | |||||||||||
| 60 | Mail::MtPolicyd::Plugin::AddScoreHeader - mtpolicyd plugin for adding the score as header to the mail | ||||||||||
| 61 | |||||||||||
| 62 | =head1 VERSION | ||||||||||
| 63 | |||||||||||
| 64 | version 2.01 | ||||||||||
| 65 | |||||||||||
| 66 | =head1 DESCRIPTION | ||||||||||
| 67 | |||||||||||
| 68 | Adds an header with the current score and score details to the mail. | ||||||||||
| 69 | |||||||||||
| 70 | =head1 PARAMETERS | ||||||||||
| 71 | |||||||||||
| 72 | =over | ||||||||||
| 73 | |||||||||||
| 74 | =item (uc_)spam_score (default: 5) | ||||||||||
| 75 | |||||||||||
| 76 | If the score is higher than this value it'll be tagged as 'YES'. | ||||||||||
| 77 | Otherwise 'NO'. | ||||||||||
| 78 | |||||||||||
| 79 | =item score_field (default: score) | ||||||||||
| 80 | |||||||||||
| 81 | Specifies the name of the field the score is stored in. | ||||||||||
| 82 | Could be set if you need multiple scores. | ||||||||||
| 83 | |||||||||||
| 84 | =item header_name (default: X-MtScore) | ||||||||||
| 85 | |||||||||||
| 86 | The name of the header to set. | ||||||||||
| 87 | |||||||||||
| 88 | =back | ||||||||||
| 89 | |||||||||||
| 90 | =head1 EXAMPLE | ||||||||||
| 91 | |||||||||||
| 92 | <Plugin add-score-header> | ||||||||||
| 93 | module = "AddScoreHeader" | ||||||||||
| 94 | # score_field = "score" | ||||||||||
| 95 | # header_name = "X-MtScore" | ||||||||||
| 96 | spam_score = 5 | ||||||||||
| 97 | </Plugin> | ||||||||||
| 98 | |||||||||||
| 99 | Will return an action like: | ||||||||||
| 100 | |||||||||||
| 101 | X-MtScore: YES score=7.5 [CTIPREP_TEMP=2.5, spamhaus-rbl=5] | ||||||||||
| 102 | |||||||||||
| 103 | =head1 AUTHOR | ||||||||||
| 104 | |||||||||||
| 105 | Markus Benning <ich@markusbenning.de> | ||||||||||
| 106 | |||||||||||
| 107 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 108 | |||||||||||
| 109 | This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>. | ||||||||||
| 110 | |||||||||||
| 111 | This is free software, licensed under: | ||||||||||
| 112 | |||||||||||
| 113 | The GNU General Public License, Version 2, June 1991 | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||