#! /usr/bin/python
#
# Copyright (C) 1998-2005 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.

"""Remove members from a list.

Usage:
    remove_members [options] [listname] [addr1 ...]

Options:

    --file=file
    -f file
        Remove member addresses found in the given file.  If file is
        `-', read stdin.

    --all
    -a
        Remove all members of the mailing list.
        (mutually exclusive with --fromall)

    --fromall
        Removes the given addresses from all the lists on this system
        regardless of virtual domains if you have any.  This option cannot be
        used -a/--all.  Also, you should not specify a listname when using
        this option.

    --nouserack
    -n
        Don't send the user acknowledgements.  If not specified, the list
        default value is used.

    --noadminack
    -N
        Don't send the admin acknowledgements.  If not specified, the list
        default value is used.

    --help
    -h
        Print this help message and exit.

    listname is the name of the mailing list to use.

    addr1 ... are additional addresses to remove.
"""

import sys
import getopt

import paths
from Mailman import MailList
from Mailman import Utils
from Mailman import Errors
from Mailman.i18n import _

try:
    True, False
except NameError:
    True = 1
    False = 0



def usage(code, msg=''):
    if code:
        fd = sys.stderr
    else:
        fd = sys.stdout
    print >> fd, _(__doc__)
    if msg:
        print >> fd, msg
    sys.exit(code)


def ReadFile(filename):
    lines = []
    if filename == "-":
        fp = sys.stdin
        closep = False
    else:
        fp = open(filename)
        closep = True
    lines = filter(None, [line.strip() for line in fp.readlines()])
    if closep:
        fp.close()
    return lines



def main():
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack'])
    except getopt.error, msg:
        usage(1, msg)

    filename = None
    all = False
    alllists = False
    # None means use list default

            sys.argv[1:], 'naf:hN',
            ['all', 'fromall', 'file=', 'help', 'nouserack', 'noadminack']