#! /usr/bin/env python
#
# Copyright (C) 1998,1999,2000 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

"""Find all lists that a member's address is on.

Usage:
    find_member [options] regex [regex [...]]

Where:
    --listname=listname
    -l listname
        Include only the named list in the search.

    --exclude=listname
    -x listname
        Exclude the named list from the search.

    --owners
    -w
        Search list owners as well as members.

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

    regex
        A Python regular expression to match against.

The interaction between -l and -x is as follows.  If any -l option is given
then only the named list will be included in the search.  If any -x option is
given but no -l option is given, then all lists will be search except those
specifically excluded.

Regular expression syntax is Perl5-like, using the Python re module.  Complete
specifications are at:

http://www.python.org/doc/current/lib/module-re.html

Address matches are case-insensitive, but case-preserved addresses are
displayed.

"""

import sys
import re
import getopt
import string

import paths
from Mailman import Utils
from Mailman import MailList
from Mailman import Errors

AS_MEMBER = 0x01
AS_OWNER = 0x02



def usage(code, msg=''):
    print __doc__ % globals()
    if msg:
        print msg
    sys.exit(code)



def scanlists(options):
    cres = []
    for r in options.regexps:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNORECASE))
    #along ws:
        cres.append(re.compile(r, re.IGNO