| 1 | package Mail::Decency::ContentFilter::CRM114; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | extends qw/ | |||||||||||||||||
| 5 | Mail::Decency::ContentFilter::Core | ||||||||||||||||||
| 6 | /; | ||||||||||||||||||
| 7 | 1 | with qw/ | |||||||||||||||||
| 8 | Mail::Decency::ContentFilter::Core::Cmd | ||||||||||||||||||
| 9 | Mail::Decency::ContentFilter::Core::Spam | ||||||||||||||||||
| 10 | Mail::Decency::ContentFilter::Core::User | ||||||||||||||||||
| 11 | Mail::Decency::ContentFilter::Core::WeightTranslate | ||||||||||||||||||
| 12 | /; | ||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 1 | ▶ | use version 0.74; our $VERSION = qv( "v0.1.6" ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 1 | ▶ | use mro 'c3'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 18 | 1 | ▶ | use File::Temp qw/ tempfile /; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | =head1 NAME | ||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | Mail::Decency::ContentFilter::CRM114 | ||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | Filters messages trough crm114 discriminator. | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | =head2 CONFIG | ||||||||||||||||||
| 29 | |||||||||||||||||||
| 30 | --- | ||||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | disable: 0 | ||||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | cmd_train: '/usr/share/crm114/mailreaver.crm --fileprefix=%user% -u %user% --report_only' | ||||||||||||||||||
| 35 | cmd_learn_spam: '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learnspam' | ||||||||||||||||||
| 36 | cmd_unlearn_spam: '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learngood' | ||||||||||||||||||
| 37 | cmd_learn_ham: '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learngood' | ||||||||||||||||||
| 38 | cmd_unlearn_ham: '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learnspam' | ||||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | # set a global crm directory .. for isp like configs, not per user | ||||||||||||||||||
| 42 | # the "/" at the end is important!! | ||||||||||||||||||
| 43 | default_user: /var/spool/crm114/ | ||||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | # weight for known innocent (good) mails | ||||||||||||||||||
| 46 | #weight_innocent: 20 | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | # weight for known spam (bad) mails | ||||||||||||||||||
| 49 | #weight_spam: -100 | ||||||||||||||||||
| 50 | |||||||||||||||||||
| 51 | # translate crm114 generated weightings into weightings | ||||||||||||||||||
| 52 | # used in the content filter context (can't use each's | ||||||||||||||||||
| 53 | # content filter out, cause they use their own scale) | ||||||||||||||||||
| 54 | # the following translated any crm114 score equal or | ||||||||||||||||||
| 55 | # bigger then 1 to 100, any score between 1 and -2 to | ||||||||||||||||||
| 56 | # internal score of 0 and anything below | ||||||||||||||||||
| 57 | weight_translate: | ||||||||||||||||||
| 58 | 1: 100 | ||||||||||||||||||
| 59 | -2: 0 | ||||||||||||||||||
| 60 | -3: -100 | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | =head2 INSTALL CRM114 | ||||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | This is a very simplified installation. For detailed information | ||||||||||||||||||
| 66 | and more in-depth information refer to google. | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | Assuming you don't want an per-user but a global css database... | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | First of get crm. In a debian system that would be: | ||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | aptitude install crm114 | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | (for source compilation or other distries refer to google) | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | Then make some crm114 directory. This might get large (depending | ||||||||||||||||||
| 77 | on the amount of trained mails) | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | mkdir /var/spool/crm114 | ||||||||||||||||||
| 80 | cd /var/spool/crm114 | ||||||||||||||||||
| 81 | |||||||||||||||||||
| 82 | Now copy the basic configuration files there | ||||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | cp /usr/share/crm114/mailfilter.cf . | ||||||||||||||||||
| 85 | |||||||||||||||||||
| 86 | Create empty priority and whitelist files | ||||||||||||||||||
| 87 | |||||||||||||||||||
| 88 | touch rewrites.mfp priolist.mfp whitelist.mfp blacklist.mfp | ||||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | Create empty css files for spam and ham | ||||||||||||||||||
| 91 | |||||||||||||||||||
| 92 | cssutil -b -r spam.css | ||||||||||||||||||
| 93 | cssutil -b -r nonspam.css | ||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | Make some modifications in the config file mailfilter.cf | ||||||||||||||||||
| 96 | (again: google for info about that matter) | ||||||||||||||||||
| 97 | |||||||||||||||||||
| 98 | :spw: /mypassword/ | ||||||||||||||||||
| 99 | :add_verbose_stats: /no/ | ||||||||||||||||||
| 100 | :add_extra_stuff: /no/ | ||||||||||||||||||
| 101 | :rewrites_enabled: /no/ | ||||||||||||||||||
| 102 | :spam_flag_subject_string: // | ||||||||||||||||||
| 103 | :unsure_flag_subject_string: // | ||||||||||||||||||
| 104 | :log_to_allmail.txt: /no/ | ||||||||||||||||||
| 105 | |||||||||||||||||||
| 106 | Mark the following for later tuning: | ||||||||||||||||||
| 107 | |||||||||||||||||||
| 108 | :good_threshold: /10.0/ | ||||||||||||||||||
| 109 | :spam_threshold: /-5.0/ | ||||||||||||||||||
| 110 | |||||||||||||||||||
| 111 | Now allow your decency filter user write-access to the config dir | ||||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | chown -R mailuser:mailgroup /var/spool/crm114 | ||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | =head2 TRAIN | ||||||||||||||||||
| 116 | |||||||||||||||||||
| 117 | Train your first mails into crm like this. | ||||||||||||||||||
| 118 | |||||||||||||||||||
| 119 | /usr/share/crm114/mailtrainer.crm --spam=/path/to/spamdir --good=/path/to/hamdir \ | ||||||||||||||||||
| 120 | --fileprefix=/var/spool/crm114/ | ||||||||||||||||||
| 121 | |||||||||||||||||||
| 122 | |||||||||||||||||||
| 123 | =head1 CLASS ATTRIBUTES | ||||||||||||||||||
| 124 | |||||||||||||||||||
| 125 | =cut | ||||||||||||||||||
| 126 | |||||||||||||||||||
| 127 | 1 | has cmd_check => ( | |||||||||||||||||
| 128 | is => 'rw', | ||||||||||||||||||
| 129 | isa => 'Str', | ||||||||||||||||||
| 130 | default => '/usr/share/crm114/mailreaver.crm --fileprefix=%user% -u %user% --report_only' | ||||||||||||||||||
| 131 | ); | ||||||||||||||||||
| 132 | |||||||||||||||||||
| 133 | 1 | has cmd_learn_spam => ( | |||||||||||||||||
| 134 | is => 'rw', | ||||||||||||||||||
| 135 | isa => 'Str', | ||||||||||||||||||
| 136 | default => '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learnspam' | ||||||||||||||||||
| 137 | ); | ||||||||||||||||||
| 138 | |||||||||||||||||||
| 139 | 1 | has cmd_unlearn_spam => ( | |||||||||||||||||
| 140 | is => 'rw', | ||||||||||||||||||
| 141 | isa => 'Str', | ||||||||||||||||||
| 142 | default => '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learngood' | ||||||||||||||||||
| 143 | ); | ||||||||||||||||||
| 144 | |||||||||||||||||||
| 145 | 1 | has cmd_learn_ham => ( | |||||||||||||||||
| 146 | is => 'rw', | ||||||||||||||||||
| 147 | isa => 'Str', | ||||||||||||||||||
| 148 | default => '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learngood' | ||||||||||||||||||
| 149 | ); | ||||||||||||||||||
| 150 | |||||||||||||||||||
| 151 | 1 | has cmd_unlearn_ham => ( | |||||||||||||||||
| 152 | is => 'rw', | ||||||||||||||||||
| 153 | isa => 'Str', | ||||||||||||||||||
| 154 | default => '/usr/share/crm114/mailfilter.crm --fileprefix=%user% -u %user% --learnspam' | ||||||||||||||||||
| 155 | ); | ||||||||||||||||||
| 156 | |||||||||||||||||||
| 157 | =head1 METHODS | ||||||||||||||||||
| 158 | |||||||||||||||||||
| 159 | |||||||||||||||||||
| 160 | =head2 handle_filter_result | ||||||||||||||||||
| 161 | |||||||||||||||||||
| 162 | =cut | ||||||||||||||||||
| 163 | |||||||||||||||||||
| 164 | 0 | ▶ | sub handle_filter_result { | ||||||||||||||||
|
Subroutine
handle_filter_result: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||
| 165 | 0 | my ( $self, $result ) = @_; | |||||||||||||||||
| 166 | |||||||||||||||||||
| 167 | 0 | my %header; | |||||||||||||||||
| 168 | |||||||||||||||||||
| 169 | # parse result | ||||||||||||||||||
| 170 | my %parsed = map { | ||||||||||||||||||
| 171 | 0 | my ( $n, $v ) = /^X-CRM114-(\S+?):\s+(.*?)$/; | |||||||||||||||||
| 172 | 0 | ( $n => lc( $v ) ); | |||||||||||||||||
| 173 | } grep { | ||||||||||||||||||
| 174 | 0 | /^X-CRM114-/; | |||||||||||||||||
| 175 | } split( /\n/, $result ); | ||||||||||||||||||
| 176 | |||||||||||||||||||
| 177 | # found status ? | ||||||||||||||||||
| 178 | 0 | ▶ | if ( $parsed{ Status } ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 179 | 0 | my $weight = 0; | |||||||||||||||||
| 180 | |||||||||||||||||||
| 181 | my $status = index( $parsed{ Status }, 'spam' ) > -1 | ||||||||||||||||||
| 182 | ? 'spam' | ||||||||||||||||||
| 183 | 0 | ▶ | : ( index( $parsed{ Status }, 'good' ) > -1 | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 184 | ? 'good' | ||||||||||||||||||
| 185 | : 'unsure' | ||||||||||||||||||
| 186 | ) | ||||||||||||||||||
| 187 | ; | ||||||||||||||||||
| 188 | 0 | my @info = ( "CRM114 status: $status" ); | |||||||||||||||||
| 189 | |||||||||||||||||||
| 190 | # translate weight from crm114 to our requirements | ||||||||||||||||||
| 191 | 0 | ▶ | if ( $self->has_weight_translate ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 192 | |||||||||||||||||||
| 193 | # extract weight | ||||||||||||||||||
| 194 | 0 | ( $weight ) = $parsed{ Status } =~ /^.*?\(\s+(\-?\d+\.\d+)\s+\).*?/; | |||||||||||||||||
| 195 | 0 | my $orig_weight = $weight; | |||||||||||||||||
| 196 | |||||||||||||||||||
| 197 | # remember info for headers | ||||||||||||||||||
| 198 | 0 | push @info, "CRM114 score: $orig_weight"; | |||||||||||||||||
| 199 | |||||||||||||||||||
| 200 | # translate weight | ||||||||||||||||||
| 201 | 0 | $weight = $self->translate_weight( $orig_weight ); | |||||||||||||||||
| 202 | |||||||||||||||||||
| 203 | 0 | $self->logger->debug0( "Translated score from '$orig_weight' to '$weight'" ); | |||||||||||||||||
| 204 | } | ||||||||||||||||||
| 205 | elsif ( $status eq 'spam' ) { | ||||||||||||||||||
| 206 | 0 | $weight = $self->weight_spam; | |||||||||||||||||
| 207 | 0 | $self->logger->debug0( "Use spam status, set score to '$weight'" ); | |||||||||||||||||
| 208 | } | ||||||||||||||||||
| 209 | elsif ( $status eq 'good' ) { | ||||||||||||||||||
| 210 | 0 | $weight = $self->weight_innocent; | |||||||||||||||||
| 211 | 0 | $self->logger->debug0( "Use good status, set score to '$weight'" ); | |||||||||||||||||
| 212 | } | ||||||||||||||||||
| 213 | |||||||||||||||||||
| 214 | # add weight to content filte score | ||||||||||||||||||
| 215 | 0 | return $self->add_spam_score( $weight, \@info ); | |||||||||||||||||
| 216 | } | ||||||||||||||||||
| 217 | |||||||||||||||||||
| 218 | else { | ||||||||||||||||||
| 219 | 0 | $self->logger->error( "Could not retreive status from CRM114 result '$result'" ); | |||||||||||||||||
| 220 | } | ||||||||||||||||||
| 221 | |||||||||||||||||||
| 222 | # return ok | ||||||||||||||||||
| 223 | 0 | return ; | |||||||||||||||||
| 224 | } | ||||||||||||||||||
| 225 | |||||||||||||||||||
| 226 | |||||||||||||||||||
| 227 | =head2 get_user_fallback | ||||||||||||||||||
| 228 | |||||||||||||||||||
| 229 | CRM114 runs normally with $USER_HOME/.crm114 .. this fallback method implements that. As long as no "cmd_user" is set, it will be used. | ||||||||||||||||||
| 230 | |||||||||||||||||||
| 231 | =cut | ||||||||||||||||||
| 232 | |||||||||||||||||||
| 233 | 0 | ▶ | sub get_user_fallback { | ||||||||||||||||
|
Subroutine
get_user_fallback: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 234 | 0 | my ( $self ) = @_; | |||||||||||||||||
| 235 | |||||||||||||||||||
| 236 | 0 | my ( $user, $domain ) = split( /@/, $self->to, 2 ); | |||||||||||||||||
| 237 | 0 | ▶ | return unless $user; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 238 | 0 | my $uid = getpwnam( $user ); | |||||||||||||||||
| 239 | 0 | ▶ | return unless $uid; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 240 | 0 | $user = ( getpwuid( $uid ) )[-2]; | |||||||||||||||||
| 241 | 0 | $user .= "/.crm114"; | |||||||||||||||||
| 242 | |||||||||||||||||||
| 243 | 0 | return $user; | |||||||||||||||||
| 244 | } | ||||||||||||||||||
| 245 | |||||||||||||||||||
| 246 | |||||||||||||||||||
| 247 | =head1 SEE ALSO | ||||||||||||||||||
| 248 | |||||||||||||||||||
| 249 | =over | ||||||||||||||||||
| 250 | |||||||||||||||||||
| 251 | =item * L<Mail::Decency::ContentFilter::Core::Cmd> | ||||||||||||||||||
| 252 | |||||||||||||||||||
| 253 | =item * L<Mail::Decency::ContentFilter::Core::Spam> | ||||||||||||||||||
| 254 | |||||||||||||||||||
| 255 | =item * L<Mail::Decency::ContentFilter::Core::WeightTranslate> | ||||||||||||||||||
| 256 | |||||||||||||||||||
| 257 | =item * L<Mail::Decency::ContentFilter::Bogofilter> | ||||||||||||||||||
| 258 | |||||||||||||||||||
| 259 | =item * L<Mail::Decency::ContentFilter::DSPAM> | ||||||||||||||||||
| 260 | |||||||||||||||||||
| 261 | =back | ||||||||||||||||||
| 262 | |||||||||||||||||||
| 263 | =head1 AUTHOR | ||||||||||||||||||
| 264 | |||||||||||||||||||
| 265 | Ulrich Kautz <uk@fortrabbit.de> | ||||||||||||||||||
| 266 | |||||||||||||||||||
| 267 | =head1 COPYRIGHT | ||||||||||||||||||
| 268 | |||||||||||||||||||
| 269 | Copyright (c) 2010 the L</AUTHOR> as listed above | ||||||||||||||||||
| 270 | |||||||||||||||||||
| 271 | =head1 LICENCSE | ||||||||||||||||||
| 272 | |||||||||||||||||||
| 273 | This library is free software and may be distributed under the same terms as perl itself. | ||||||||||||||||||
| 274 | |||||||||||||||||||
| 275 | =cut | ||||||||||||||||||
| 276 | |||||||||||||||||||
| 277 | 1 | 1; | |||||||||||||||||