Re: Using SpamAssassin to parse Received headers
> Look in man perldoc Mail::SpamAssassin::Plugin for the definition of a > new plugin (for example MyFilter) > > You could do a lot of interesting things inside the plugin > with the Mail::SpamAssassin::PerMsgStatus element (again perldoc ...) Hi Leonardo, I think this example might be more suited towards creating a new SA plugin, right? That's not at all what I'm trying to do here - this isn't part of the mail stream, this is a standalone perl program. I just want to take advantage of SA's excellent Received header parsing to get the IP addresses for the relays. Basically, here's what I'm trying to do: 1) Connect to DB 2) Grab the full text of an email into a variable 3) Use SA's code to parse the headers 4) Grab the IP addresses from the Received headers #3 and #4 are where I'm having issues, because I don't understand the code (and I suck pretty bad at Perl). Thanks, and hope that clears up my problem, Benny -- "This officer's men seem to follow him merely out of idle curiosity." -- Sandhurst officer cadet evaluation
Re: Using SpamAssassin to parse Received headers
Hi Look in man perldoc Mail::SpamAssassin::Plugin for the definition of a new plugin (for example MyFilter) You could do a lot of interesting things inside the plugin with the Mail::SpamAssassin::PerMsgStatus element (again perldoc ...) A rough example (this works for older spamassassin, you really should look at those man pages) package Mail::SpamAssassin::Plugin::MyExampleFilter; use Mail::SpamAssassin::Plugin; use strict; use warnings; use vars qw(@ISA); @ISA = qw(Mail::SpamAssassin::Plugin); # constructor: register the eval rule sub new { my $class = shift; my $mailsaobject = shift; # some boilerplate... $class = ref($class) || $class; my $self = $class->SUPER::new($mailsaobject); bless ($self, $class); # the important bit! $self->register_eval_rule ("my_example_filter"); return $self; } # and the eval rule itself sub my_example_filter { my ($self, $permsgstatus) = @_; Mail::SpamAssassin::dbg("myexamplefilter: processing " . join( ", ", $pe rmsgstatus->get('MESSAGEID') ) . " Envelope From=" . $permsgstatus->get('Envelo peFrom') ); return 0; } And finaly in a .cf loadplugin Mail::SpamAssassin::Plugin::MyExampleFilter header MYEXAMPLEFILTER eval:my_example_filter() (You could put plugin configs here also) I think this question has been answered a couple of times, probably in a better way than this. Saludos -- Leonardo Helman Pert Consultores Argentina On Tue, Aug 14, 2007 at 03:15:04PM -0500, C. Bensend wrote: > > Hey folks, > >This is a question about using SpamAssassin's perl interface, not > about filtering mail. > >I'm using 3.2.2 (soon to be 3.2.3) on OpenBSD, built from source. > In addition to using SA to filter my email, I'd also like to take > advantage of SA's ability to parse Received headers for my own > project. > >I store the entire spam in a database. What I want to do is to > be able to parse out the Received headers' IP addresses from the > full text of each email. I only really need the IP that hands off > to my own servers, but it would be useful to get an array of all of > them. > >I am not at all a perl guru - I've written quite a bit of it, > but more complex stuff than my simple scratchings makes my brain > swell and hurt. If someone could give me a quick leg up in going > from a variable containing the entire message to an array of IPs > (or just the handoff IP, that's fine), I'd really appreciate it. > > Thanks a bunch! > > Benny > > > -- > "This officer's men seem to follow him merely out of idle curiosity." >-- Sandhurst officer cadet evaluation
Re: Using SpamAssassin to parse Received headers
Hi Look in man perldoc Mail::SpamAssassin::Plugin for the definition of a new plugin (for example MyFilter) You could do a lot of interesting things inside the plugin with the Mail::SpamAssassin::PerMsgStatus element (again perldoc ...) A rough example (this works for older spamassassin, you really should look at those man pages) package Mail::SpamAssassin::Plugin::MyExampleFilter; use Mail::SpamAssassin::Plugin; use strict; use warnings; use vars qw(@ISA); @ISA = qw(Mail::SpamAssassin::Plugin); # constructor: register the eval rule sub new { my $class = shift; my $mailsaobject = shift; # some boilerplate... $class = ref($class) || $class; my $self = $class->SUPER::new($mailsaobject); bless ($self, $class); # the important bit! $self->register_eval_rule ("my_example_filter"); return $self; } # and the eval rule itself sub my_example_filter { my ($self, $permsgstatus) = @_; Mail::SpamAssassin::dbg("myexamplefilter: processing " . join( ", ", $permsgstatus->get('MESSAGEID') ) . " Envelope From=" . $permsgstatus->get('EnvelopeFrom') ); return 0; } And finaly in a .cf loadplugin Mail::SpamAssassin::Plugin::MyExampleFilter header MYEXAMPLEFILTER eval:my_example_filter() (You could put plugin configs here also) I think this question has been answered a couple of times, probably in a better way than this. Saludos -- Leonardo Helman Pert Consultores Argentina On Tue, Aug 14, 2007 at 03:15:04PM -0500, C. Bensend wrote: > > Hey folks, > >This is a question about using SpamAssassin's perl interface, not > about filtering mail. > >I'm using 3.2.2 (soon to be 3.2.3) on OpenBSD, built from source. > In addition to using SA to filter my email, I'd also like to take > advantage of SA's ability to parse Received headers for my own > project. > >I store the entire spam in a database. What I want to do is to > be able to parse out the Received headers' IP addresses from the > full text of each email. I only really need the IP that hands off > to my own servers, but it would be useful to get an array of all of > them. > >I am not at all a perl guru - I've written quite a bit of it, > but more complex stuff than my simple scratchings makes my brain > swell and hurt. If someone could give me a quick leg up in going > from a variable containing the entire message to an array of IPs > (or just the handoff IP, that's fine), I'd really appreciate it. > > Thanks a bunch! > > Benny > > > -- > "This officer's men seem to follow him merely out of idle curiosity." >-- Sandhurst officer cadet evaluation
Re: Using SpamAssassin to parse Received headers
> Hey folks, > > This is a question about using SpamAssassin's perl > interface, not about filtering mail. > > I'm using 3.2.2 (soon to be 3.2.3) on OpenBSD, built > from source. In addition to using SA to filter my email, > I'd also like to take advantage of SA's ability to parse > Received headers for my own project. > I think looking at Botnet.pm plugin would give some hints to you. Not a perl guru myself, though..
Using SpamAssassin to parse Received headers
Hey folks, This is a question about using SpamAssassin's perl interface, not about filtering mail. I'm using 3.2.2 (soon to be 3.2.3) on OpenBSD, built from source. In addition to using SA to filter my email, I'd also like to take advantage of SA's ability to parse Received headers for my own project. I store the entire spam in a database. What I want to do is to be able to parse out the Received headers' IP addresses from the full text of each email. I only really need the IP that hands off to my own servers, but it would be useful to get an array of all of them. I am not at all a perl guru - I've written quite a bit of it, but more complex stuff than my simple scratchings makes my brain swell and hurt. If someone could give me a quick leg up in going from a variable containing the entire message to an array of IPs (or just the handoff IP, that's fine), I'd really appreciate it. Thanks a bunch! Benny -- "This officer's men seem to follow him merely out of idle curiosity." -- Sandhurst officer cadet evaluation