#!/usr/bin/perl
# $Id: caddmailList,v 1.1 2001/08/20 19:42:55 jeffb Exp $
# Copyright (c) 1999,2000 Cobalt Networks, Inc. 
# http://www.cobalt.com/
#
use strict;
$0 = "caddmailList";

use lib qw(/usr/sausalito/perl);

require ShellCfg;
require Shell;
use Getopt::Std;

my $opts = {};
getopts('n:u:s:r:m:p:a:l:b:o:q:eh', $opts);

if ($opts->{h} || !$opts->{n}) {
	usage();
}
my $mlRef = ShellCfg::mapOpts('mailListAdd', $opts);

# connect to CCE
my $cce = new Shell;
$cce->connectuds();

# strip out the other stuff
my $archRef;
if($mlRef->{Archive}) {
	$archRef = $mlRef->{Archive};
	$archRef->{enabled} = 'true';
}
$mlRef = ShellCfg::stripRef($mlRef);

if(exists($mlRef->{local_recips})) {
	$mlRef->{local_recips} = $cce->validateUsers($mlRef->{local_recips});
}
if(exists($mlRef->{remote_recips})) {
	$mlRef->{remote_recips} = $cce->scalar_to_scalar($mlRef->{remote_recips});
}
if(exists($mlRef->{maxlength})) {
	$mlRef->{maxlegth} = ShellCfg::convertByte($mlRef->{maxlegth});
}
if(exists($mlRef->{replyToList})) {
	$mlRef->{replyToList} = '0';
}

use Data::Dumper;
print Dumper($mlRef);
# create the user
$cce->create("MailList", $mlRef);

# if we get here, we must set other data related to the user
my $oid = $cce->oid();

if ($archRef) {
	$cce->set($oid, "Archive", $archRef);
} 

warn "\nMail List ", $mlRef->{name}, " has been created.\n";
$cce->bye("shine on you crazy diamond");
exit 0;

sub usage 
{
print <<EOF;
$0: Copyright (c) 1999,2000,2001 Cobalt Networks, Inc.
usage: $0 [-n mail list name] [-u users] [-s remote users]
		[-q size] [-r remarks] [-m user name] [-p password] 
		[-e] [-b open|confirm|closed] [-o members|any|moderated]

        -n The mailing list name you want to create
        -u list of user names to add to the mailing list, comma delimited
        -s list of remote subscribers to the mailing list, comma delimited
        -r group's remarks
		-q Maximum message lenght
		-m moderator name
		-p moderator password
		-e reply to sender (default reply to list)
		-b Subscription policy: open, confirm, closed (default confirm)
		-o Posting policy: members, any, moderated (default members)
        -h show this help
EOF
    exit 0;
}


