#!/usr/bin/eperl

###
#
# Copyright (c) Ensim Corporation 2000, 2001   All Rights Reserved.
#
# This software is furnished under a license and may be used and copied
# only  in  accordance  with  the  terms  of such  license and with the
# inclusion of the above copyright notice. This software or any other
# copies thereof may not be provided or otherwise made available to any
# other person. No title to and ownership of the software is hereby
# transferred.
#
# The information in this software is subject to change without notice
# and  should  not be  construed  as  a commitment by Ensim Corporation.
# Ensim assumes no responsibility for the use or  reliability  of its
# software on equipment which is not supplied by Ensim.
#
# --------------------------------------------------------------------------
# $Id: add_members,v 1.1.1.1 2008-03-01 00:21:36 aarefyev Exp $
# $Name: not supported by cvs2svn $
# --------------------------------------------------------------------------
# add_members :
# Usage: add_members ...
# -------------------------------------------------------

push @INC, ($ENV{'OCW_SVCPATH'} || "/usr/lib/opcenter")."/majordomo";
push @INC, ($ENV{'OCW_SVCPATH'} || "/usr/lib/opcenter")."/cmdline_common";
push @INC, ($ENV{'OCW_SVCPATH'} || "/usr/lib/opcenter")."/sendmail";

require 'CmdLineCoder.pm';
require 'mymajordomo-lib.pl';
require 'majordomo.pm';

local $in;
local @in;
# Decode the string argument before performing any vodoo on it
&CmdLineCoder::decode_args();
$in = $ARGV[0];
@in = &majordomo::stringToList($in);

# contains the name of the mailing list and a list of new memberaddrs
$name = $in[0];
# the remaining members are the email addrs of the new memebrs
shift(@in);
local @newMembers = @in;

$list = &majordomo::get_list($name, &get_config());
$conf =  &get_list_config($list->{'config'});
$pass = &find_value("admin_passwd",$conf);

$sender_name = &find_value("sender",$conf);
$mlsender = &get_alias_name($sender_name);

#$ldir = '/var/lib/majordomo/lists';

# get rid of empty values in the list of new members
@newMembers = grep { /^\s*\S+\s*$/ } @newMembers;

# call majordomo to subscribe the address on new members
foreach $m (@newMembers) {
  if ($m) {
      open(WRAPPER, "|$config{'program_dir'}/wrapper majordomo");
      print WRAPPER "From: $mlsender\n\n";
      print WRAPPER "approve $pass subscribe $name $m \n\n";
      close(WRAPPER);
  }
}
exit(0);
