#!%PERL% -w 


use strict;

use Data::Dumper;
use lib '%VHFFS_LIB_DIR%';
use Vhffs::Main;
use Vhffs::Services::Mail;

my $princ = init Vhffs::Main;

die("Usage: $0 mxdomain localpart remote_address\n") unless(@ARGV == 3);

my ($domain, $local, $remote) = @ARGV;

my $mail = Vhffs::Services::Mail::get_by_mxdomain($princ, $domain);

die("Mail domain $domain not found\n") unless(defined $mail);


if( $mail->addforward($local, $remote) < 0 )
{
    die "Unable to add forward $local\@". $mail->get_domain ." -> $remote\n";
}

print "Forward created\n";
