~sumanah/mailman/mailman

« back to all changes in this revision

Viewing changes to src/mailman/runners/lmtp.py

  • Committer: Sumana Harihareswara
  • Date: 2015-01-08 21:35:58 UTC
  • mfrom: (7273.2.15 3.0)
  • Revision ID: sumanah@panix.com-20150108213558-65ym6553zj256z8p
mergeĀ fromĀ master

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2014 by the Free Software Foundation, Inc.
 
1
# Copyright (C) 2006-2015 by the Free Software Foundation, Inc.
2
2
#
3
3
# This file is part of GNU Mailman.
4
4
#
34
34
    http://www.faqs.org/rfcs/rfc2033.html
35
35
"""
36
36
 
37
 
from __future__ import absolute_import, print_function, unicode_literals
38
 
 
39
 
__metaclass__ = type
40
37
__all__ = [
41
38
    'LMTPRunner',
42
39
    ]
48
45
import asyncore
49
46
 
50
47
from email.utils import parseaddr
51
 
from zope.component import getUtility
52
 
 
53
48
from mailman.config import config
54
49
from mailman.core.runner import Runner
55
50
from mailman.database.transaction import transactional
57
52
from mailman.interfaces.listmanager import IListManager
58
53
from mailman.utilities.datetime import now
59
54
from mailman.utilities.email import add_message_hash
 
55
from zope.component import getUtility
60
56
 
61
57
 
62
58
elog = logging.getLogger('mailman.error')
91
87
    )
92
88
 
93
89
DASH    = '-'
94
 
CRLF    = b'\r\n'
95
 
ERR_451 = b'451 Requested action aborted: error in processing'
96
 
ERR_501 = b'501 Message has defects'
97
 
ERR_502 = b'502 Error: command HELO not implemented'
98
 
ERR_550 = b'550 Requested action not taken: mailbox unavailable'
99
 
ERR_550_MID = b'550 No Message-ID header provided'
 
90
CRLF    = '\r\n'
 
91
ERR_451 = '451 Requested action aborted: error in processing'
 
92
ERR_501 = '501 Message has defects'
 
93
ERR_502 = '502 Error: command HELO not implemented'
 
94
ERR_550 = '550 Requested action not taken: mailbox unavailable'
 
95
ERR_550_MID = '550 No Message-ID header provided'
100
96
 
101
97
# XXX Blech
102
 
smtpd.__version__ = b'Python LMTP runner 1.0'
 
98
smtpd.__version__ = 'Python LMTP runner 1.0'
103
99
 
104
100
 
105
101
 
147
143
        """HELO is not a valid LMTP command."""
148
144
        self.push(ERR_502)
149
145
 
 
146
    ## def push(self, arg):
 
147
    ##     import pdb; pdb.set_trace()
 
148
    ##     return super().push(arg)
 
149
 
150
150
 
151
151
 
152
152
class LMTPRunner(Runner, smtpd.SMTPServer):
202
202
        for to in rcpttos:
203
203
            try:
204
204
                to = parseaddr(to)[1].lower()
205
 
                listname, subaddress, domain = split_recipient(to)
 
205
                local, subaddress, domain = split_recipient(to)
206
206
                slog.debug('%s to: %s, list: %s, sub: %s, dom: %s',
207
 
                           message_id, to, listname, subaddress, domain)
208
 
                listname += '@' + domain
 
207
                           message_id, to, local, subaddress, domain)
 
208
                listname = '{}@{}'.format(local, domain)
209
209
                if listname not in listnames:
210
210
                    status.append(ERR_550)
211
211
                    continue
 
212
                listid = '{}.{}'.format(local, domain)
212
213
                # The recipient is a valid mailing list.  Find the subaddress
213
214
                # if there is one, and set things up to enqueue to the proper
214
215
                # queue.
215
216
                queue = None
216
 
                msgdata = dict(listname=listname,
 
217
                msgdata = dict(listid=listid,
217
218
                               original_size=msg.original_size,
218
219
                               received_time=received_time)
219
220
                canonical_subaddress = SUBADDRESS_NAMES.get(subaddress)
243
244
                    config.switchboards[queue].enqueue(msg, msgdata)
244
245
                    slog.debug('%s subaddress: %s, queue: %s',
245
246
                               message_id, canonical_subaddress, queue)
246
 
                    status.append(b'250 Ok')
 
247
                    status.append('250 Ok')
247
248
            except Exception:
248
249
                slog.exception('Queue detection: %s', msg['message-id'])
249
250
                config.db.abort()