#!%PERL% -w


use strict;

use Data::Dumper;
use lib '%VHFFS_LIB_DIR%';
use Vhffs::Conf;
use Vhffs::User;
use Vhffs::Group;
use Vhffs::Main;
use Vhffs::Object;
use Vhffs::Services::Mail;
use Vhffs::Services::MailingList;

my $princ = init Vhffs::Main;

die("Usage: $0 local_part domain admin_email description owner_username owner_groupname\n") unless(@ARGV == 6);

my ($local, $domain, $admin, $description, $username, $groupname) = @ARGV;

my $user = Vhffs::User::get_by_username($princ, $username);
die("User not found\n") unless(defined $user);
my $group = Vhffs::Group::get_by_groupname($princ, $groupname);
die("Group not found\n") unless(defined $group);

my $mail = Vhffs::Services::MailingList::create($princ, $local, $domain, $admin, $description, $user, $group);

if( defined $mail )
{
	print "Mailing list $local\@$domain created\n";
}
else
{
	die("Unable to create mailing list $local\@$domain, please check syntax and uniqueness\n");
}

