=head1 NAME

Mail::SpamAssassin::Plugin::FromRealName - check real name in header From

=head1 SYNOPSIS

  loadplugin     Mail::SpamAssassin::Plugin::FromRealName

  header		__FROM_UNDERSCORED     	eval:check_underscored_From()
  header		__FROM_DOTTED     	eval:check_dotted_From()
  header		__FROM_MINUS     	eval:check_minus_From()

=head1 DESCRIPTION


=cut

package Mail::SpamAssassin::Plugin::FromRealName;

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_underscored_From");
  $self->register_eval_rule("check_dotted_From");
  $self->register_eval_rule("check_minus_From");

  return $self;
}

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

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

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

1;
