#! /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.

"""Dispatch digests for lists w/pending messages and digest_send_periodic set.

Typically it's invoked via cron.
"""

import sys
import os
from stat import ST_SIZE
from errno import ENOENT
import paths
from Mailman import MailList
from Mailman import cal)
    local = re.sub("^" + MailmanUser + "-","",local)

    names = ("root", "postmaster", "mailer-daemon", "mailman-owner", "owner",
             "abuse")
    for i in names:
        if i == local:
            os.execv("/var/qmail/bin/qmail-inject",
                     ("/var/qmail/bin/qmail-inject", MailmanOwner))
            sys.exit(0)

    type = "post"
    types = (("-admin$", "mailowner"),
             ("-owner$", "mailowner"),
             ("-request$", "mailcmd"))

    for i in types:
        if re.search(i[0],local):
            type = i[1]
            local = re.sub(i[0],"",local)

    if os.path.exists(local):
        os.execv(MailmanHome + "/mail/wrapper",
                 (MailmanHome + "/mail/wrapper", type, local))
    else:
        bounce()
    sys.exit(111)

def bounce():
    bounce_message = """\
TO ACCESS THE MAILING LIST SYSTEM: Start your web browser on
http://%s/
That web page will help you subscribe or unsubscribe, and will
give you directions on how to p