package PublicCheck::FlatStore; use strict; use PublicCheck::MidStore; use IO::File; our(@ISA) = qw(PublicCheck::MidStore); our($CONF_KEY) = 'PublicCheck'; sub new { my($this,$plugin) = (shift,shift); $plugin->debug("Using conf key: $CONF_KEY"); my($self) = $this->SUPER::new($plugin); return($self); } sub parse_config { my($self,$plugin,$opt) = (shift,shift,shift); my($key) = $opt->{key}; if($key eq 'outbound_mid_log'){ my($val) = $opt->{value}; $opt->{conf}{$CONF_KEY}{outbound_mid_log} = $val; $plugin->inhibit_further_callbacks(); return(1); } return(0); } sub exists { my($self,$plugin,$pmstat,$mid,$email) = (shift,shift,shift,shift,shift); $email ||=0; my($conf) = $plugin->{main}{conf}{$CONF_KEY}; #Our configuration area. my($file) = $conf->{'outbound_mid_log'} || 0; if(! $file){ $plugin->debug(" config 'outbound_mid_log' NOT set, can't check for message ID's"); return(0); } $plugin->debug("Using: [$file] as a log of all outbound message ID's"); if(! -e $file){ $plugin->debug("but, [$file] does not exist, skipping check"); return(0); } my($handle) = new IO::File($file); if(! $handle){ $plugin->debug("Can't open [$file]:$! (skipping check)"); return(0); } my($found) = 0; while($_ = $handle->getline()){ chomp; s/^\s//g; if(/^\#/){ next; } my($id,$ad,$g) = split(/\s+/,$_,3); # We use a $g in case the flat file stores more. if($id eq $mid){ if($email){ $plugin->debug("using a 'strict' level, so, check [$email] == [$ad]"); $found = ($email eq $ad); }else{ $found = 1; } last; } } if(! $found){ $plugin->debug("Couldn't find $mid, spam?"); }else{ $plugin->debug("We have a match: File:[$file] Mid:[$mid] Email:[$email]"); } $handle->close(); return($found); } 1; __END__ =pod =head1 NAME PublicCheck::FlatStore =head SYNOPSIS # Tell PublicCheck::To that we're using a FlatStore module. public_store_module PublicCheck::FlatStore # File containing email@example.com Comments. outbound_mid_log /path/to/outbound_message/id/log =head DESCRIPTION This is a dumb storage implementation, probably should be using something else. It is uses a flat logfile of message ID's and email addresses. Good for testing, though. =cut