#!/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: list_mlistMembers,v 1.1.1.1 2008-03-01 00:21:36 aarefyev Exp $
# $Name: not supported by cvs2svn $
# --------------------------------------------------------------------------
# remove_mlist : It removes a maling list from the server
# (after asking the user if he is sure)
# Usage: remove_mlist <mailing-list name>
# -------------------------------------------------------

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

require '/usr/lib/opcenter/cmdline_common/CmdLineCoder.pm';
require '/usr/lib/opcenter/majordomo/mymajordomo-lib.pl';
require '/usr/lib/opcenter/majordomo/majordomo.pm';

use English;

sub GetSiteOwner {
  my (@retval) = ();
  @file_stat = lstat("/home");
  $uid = $file_stat[4];
  $gid = $file_stat[5];
  @retval = ($uid, $gid);
  return @retval;
}

sub GetOwnerAccess {
  my (@retval) = ();
  @retval = ($EFFECTIVE_USER_ID, $EFFECTIVE_GROUP_ID);
  return @retval;
}

sub DemoteOwnerAccess {
  my ($site_uid, $site_gid) = (0, 0);
  ($site_uid, $site_gid) = &GetSiteOwner();
  $EFFECTIVE_GROUP_ID = $site_gid;
  $EFFECTIVE_USER_ID = $site_uid;
}

sub PromoteOwnerAccess {
  my ($site_uid, $site_gid) = @_;
  $EFFECTIVE_USER_ID = $site_uid;
  $EFFECTIVE_GROUP_ID = $site_gid;
}

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

# contains the name of the mailing list to be removed
$in =~ s/\s+//;


# get list of members
local $memberlist; 
$conf = &get_config();
#$ldir = &perl_var_replace(&find_value("listdir", $conf), $conf);
$myos = &getMyOS();
if ($myos eq "Linux") { 
$ldir = '/var/lib/majordomo/lists';
$newalias_path= '/usr/bin/newalias';
}
else {
$ldir = '/usr/local/majordomo/lists';
$newalias_path= '/usr/local/etc/mail/newaliases';
}

&DemoteOwnerAccess();

open(CURR,"<$ldir/$in");

@curr = <CURR>;
foreach $line (@curr)
 {
   chop $line;
   # also remove whitespace from beginning and end of the emailddr
   push(@memberlist, $line);
 }


#need to encode this list
local $rv="";
foreach $l (@memberlist) {
	# using & as the delim
	$rv = "$rv" . CmdLineCoder::encode_string("$l") . "&";
}
chop($rv);
print $rv, "\n";

