
package RT::Action::NotifyOldOwner;
require RT::Action::Notify;
@ISA = qw(RT::Action::Notify);


sub SetRecipients {
    my $self=shift;

    $arg=$self->Argument;

    $arg =~ s/\bAll\b/OldOwner/;

    my (@To);

    if ($arg =~ /\bOldOwner\b/) {
        if ($self->TransactionObj->OldValue != $RT::Nobody->Id) {
        my $OldOwner=new RT::User($RT::SystemUser);

        $OldOwner->Load($self->TransactionObj->OldValue);
        push(@To, $OldOwner->EmailAddress);

        $self->SUPER::SetRecipients ();

        my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
        # override possible 'To'
        @{$self->{'To'}} = grep (!/^$creator$/, @To);
        }
    }

return (1);
}

sub SetReturnAddress {
	my $self = shift;
	
	# Tell RT::Action::SendEmail that this should come 
	# from the relevant comment email address.
	$self->{'comment'} = 1;
	
	return($self->SUPER::SetReturnAddress(is_comment => 1));
}

# {{{ sub IsApplicable
sub IsApplicable  {
  my $self = shift;

  return (1) if ($self->TransactionObj->Field eq 'Owner');
  return (undef);
}
# }}}


1;

