3 # Copyright (C) 2000,2001,2002 by the Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 """Automatically send a message to a mailing list.
22 # To use with Postfix, set the following in your main.cf file:
24 # recipient_delimiter = +
25 # luser_relay = mm+$user@yourdomain.com
26 # owner_request_special = no
33 from Mailman import mm_cfg
34 from Mailman import Utils
35 from Mailman import MailList
36 from Mailman import Errors
37 from Mailman.Queue.sbcache import get_switchboard
38 from Mailman.Logging.Utils import LogStdErr
40 # Error code if it's really not a Mailman list addr destination
43 LogStdErr('auto', 'auto')
45 DISPOSE_MAP = {None : 'tolist',
46 'request': 'torequest',
53 def fqdn_listname(listname, hostname):
54 return ('%s@%s' % (listname, hostname)).lower()
59 # Postfix sets some environment variables based on information gleaned
60 # from the original message. This is the most direct way to figure out
61 # which list the message was intended for.
62 extension = os.environ.get('EXTENSION', '').lower()
63 i = extension.rfind('-')
69 listname = extension[:i]
70 subdest = DISPOSE_MAP.get(extension[i+1:], missing)
71 if not Utils.list_exists(listname) or subdest is missing:
72 # must be a list that has a `-' in it's name
76 print >> sys.stderr, 'Empty list name (someone being subversive?)'
79 mlist = MailList.MailList(listname, lock=0)
80 except Errors.MMListError:
81 print >> sys.stderr, 'List not found:', listname
84 # Make sure that the domain part of the incoming address matches the
85 # domain of the mailing list. Actually, it's possible that one or the
86 # other is more fully qualified, and thus longer. So we split the domains
87 # by dots, reverse them and make sure that whatever parts /are/ defined
88 # for both are equivalent.
89 domain = os.environ.get('DOMAIN', '').lower()
90 domainp = domain.split('.')
91 hostname = mlist.host_name.split('.')
94 for ca, cb in zip(domainp, hostname):
96 print >> sys.stderr, 'Domain mismatch: %s@%s (expected @%s)' \
97 % (listname, domain, mlist.host_name)
101 print >> sys.stderr, 'Bad sub-destination:', extension
104 inq = get_switchboard(mm_cfg.INQUEUE_DIR)
105 inq.enqueue(sys.stdin.read(),
107 received_time=time.time(),
114 if __name__ == '__main__':