=head1 NAME

Mail::SpamAssassin::Plugin::RealName - check real name in addresses headers

=head1 SYNOPSIS

  loadplugin     Mail::SpamAssassin::Plugin::RealName

  header		__FROM_UNDERSCORED     	eval:check_real_name_mailbox('From', '_')
  header		__FROM_DOTTED     	eval:check_real_name_mailbox('From', '.')
  header		__FROM_MINUS     	eval:check_real_name_mailbox('From', '-')

=head1 DESCRIPTION


=cut

package Mail::SpamAssassin::Plugin::RealName;

use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::Logger;
use Fcntl;
use strict;
use warnings;
use bytes;

use vars qw(@ISA);
@ISA = qw(Mail::SpamAssassin::Plugin);

sub new {
  my $class = shift;
  my $mailsaobject = shift;

  $class = ref($class) || $class;
  my $self = $class->SUPER::new($mailsaobject);
  bless ($self, $class);

  $self->register_eval_rule("check_real_name_mailbox");

  return $self;
}

sub check_real_name_mailbox {
  my ($self, $permsgstatus, $header, $excluded_chars) = @_;
  local ($_);
  $_ = $permsgstatus->get($header);
  if (/^(\s*\S+)(\s*<.+>)/) {
    my $realname = $1;
    my $addr = $2;
    $realname =~ s/[$excluded_chars]//g if ($excluded_chars);
    $addr = $realname.$addr;
    return($addr =~ /^\s*(\S+)\s*<\1\@.+>/i ? 1 : 0);
  } else {
    return 0;
  }
}

1;
