Karl-Aksel Puulmann has proposed merging
lp:~macobo/mailman/macobo-rcpt-stage-reject into lp:mailman.
Requested reviews:
Mailman Coders (mailman-coders)
Related bugs:
Bug #982555 in GNU Mailman: "LMTP should reject unknown lists in RCPT-stage"
https://bugs.launchpad.net/mailman/+bug/982555
For more details, see:
https://code.launchpad.net/~macobo/mailman/macobo-rcpt-stage-reject/+merge/157516
It probably needs a little more work before merging.
Open questions:
1) Is the test naming okay?
2) Should the tests be done in a different way? I didn't find any other tests
that used the mock library.
3) Should the mocking be done within the setUp stage?
4) If that's okay, should get_mocked_lmtp_channel be moved to tests/helpers.py?
--
https://code.launchpad.net/~macobo/mailman/macobo-rcpt-stage-reject/+merge/157516
Your team Mailman Coders is requested to review the proposed merge of
lp:~macobo/mailman/macobo-rcpt-stage-reject into lp:mailman.
=== modified file 'src/mailman/runners/lmtp.py'
--- src/mailman/runners/lmtp.py 2013-01-20 21:23:09 +0000
+++ src/mailman/runners/lmtp.py 2013-04-06 14:30:27 +0000
@@ -147,6 +147,24 @@
"""HELO is not a valid LMTP command."""
self.push(ERR_502)
+ def smtp_RCPT(self, arg):
+ if not self._SMTPChannel__mailfrom:
+ self.push(b'503 Error: need MAIL command')
+ return
+ address = self._SMTPChannel__getaddr('TO:', arg) if arg else None
+ if not address:
+ self.push(b'501 Syntax: RCPT TO: <address>')
+ return
+ # Refresh the list of list names every time we process a message
+ # since the set of mailing lists could have changed.
+ listnames = set(getUtility(IListManager).names)
+ listname, subaddress, domain = split_recipient(address)
+ listname = listname.lower() + '@' + domain
+ if listname not in listnames:
+ self.push(ERR_550)
+ return
+ self._SMTPChannel__rcpttos.append(address)
+ self.push(b'250 Ok')
class LMTPRunner(Runner, smtpd.SMTPServer):
=== modified file 'src/mailman/runners/tests/test_lmtp.py'
--- src/mailman/runners/tests/test_lmtp.py 2013-03-06 21:59:15 +0000
+++ src/mailman/runners/tests/test_lmtp.py 2013-04-06 14:30:27 +0000
@@ -12,6 +12,8 @@
# 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
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
@@ -29,8 +31,10 @@
import smtplib
import unittest
+from mock import Mock
from datetime import datetime
+from mailman.runners.lmtp import Channel
from mailman.config import config
from mailman.app.lifecycle import create_list
from mailman.database.transaction import transaction
@@ -38,6 +42,14 @@
from mailman.testing.layers import LMTPLayer
+def get_mocked_lmtp_channel():
+ connection = Mock()
+ connection.getpeername = Mock(return_value='FakePeer')
+ channel = Channel(None, connection, None)
+ channel.push = Mock()
+ return channel
+
+
class TestLMTP(unittest.TestCase):
"""Test various aspects of the LMTP server."""
@@ -144,3 +156,23 @@
self.assertEqual(len(messages), 1)
self.assertEqual(messages[0].msgdata['listname'],
'[email protected]')
+
+ def test_lp982555_RCPT_before_mail(self):
+ channel = get_mocked_lmtp_channel()
+ channel.smtp_RCPT('TO: <[email protected]>')
+ channel.push.assert_called_with('503 Error: need MAIL command')
+
+ def test_lp982555_RCPT_existing_list(self):
+ with transaction():
+ create_list('[email protected]')
+ channel = get_mocked_lmtp_channel()
+ channel.smtp_MAIL('FROM: [email protected]')
+ channel.smtp_RCPT('TO: <[email protected]>')
+ channel.push.assert_called_with('250 Ok')
+
+ def test_lp982555_RCPT_nonexisting_list(self):
+ channel = get_mocked_lmtp_channel()
+ channel.smtp_MAIL('FROM: [email protected]')
+ channel.smtp_RCPT('TO: <[email protected]>')
+ channel.push.assert_called_with(
+ '550 Requested action not taken: mailbox unavailable')
_______________________________________________
Mailman-coders mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-coders