Clean up the mta directory.
[mailman.git] / src / mailman / runners / incoming.py
blob6d576cb5056610c230a62ff65b0917ae0ce2405e
1 # Copyright (C) 1998-2016 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
8 # any later version.
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Incoming runner.
20 This runner's sole purpose in life is to decide the disposition of the
21 message. It can either be accepted for delivery, rejected (i.e. bounced),
22 held for moderator approval, or discarded.
24 When accepted, the message is forwarded on to the `prep queue` where it is
25 prepared for delivery. Rejections, discards, and holds are processed
26 immediately.
27 """
29 __all__ = [
30 'IncomingRunner',
34 from mailman.core.chains import process
35 from mailman.core.runner import Runner
36 from mailman.database.transaction import transaction
37 from mailman.interfaces.address import ExistingAddressError
38 from mailman.interfaces.usermanager import IUserManager
39 from zope.component import getUtility
43 class IncomingRunner(Runner):
44 """The incoming runner."""
46 def _dispose(self, mlist, msg, msgdata):
47 """See `IRunner`."""
48 if msgdata.get('envsender') is None:
49 msgdata['envsender'] = mlist.no_reply_address
50 # Ensure that the email addresses of the message's senders are known
51 # to Mailman. This will be used in nonmember posting dispositions.
52 user_manager = getUtility(IUserManager)
53 with transaction():
54 for sender in msg.senders:
55 try:
56 user_manager.create_address(sender)
57 except ExistingAddressError:
58 pass
59 # Process the message through the mailing list's start chain.
60 start_chain = (mlist.owner_chain
61 if msgdata.get('to_owner', False)
62 else mlist.posting_chain)
63 process(mlist, msg, msgdata, start_chain)
64 # Do not keep this message queued.
65 return False