Commits

"Fel...@schwarz.eu>"  committed a62a4f6

All data collected so far can be retrieved from the Message object

  • Participants
  • Parent commits a5f0a54

Comments (0)

Files changed (3)

File pymta/model.py

         self.msg_data = msg_data
 
 
+
 class Peer(object):
     def __init__(self, remote_ip, remote_port):
         self.remote_ip = remote_ip

File pymta/processor.py

 
 from repoze.workflow.statemachine import StateMachine, StateMachineError
 
-from pymta.model import Message
+from pymta.model import Message, Peer
 
 __all__ = ['SMTPProcessor']
 
         self._command_arguments = None
         self._message = None
         
-        self.remote_ip_string = None
-        self.remote_port = None
         self._build_state_machine()
         
     
         """This method is called when a new SMTP session is opened.
         [PUBLIC API]
         """
-        self.remote_ip_string = remote_ip
-        self.remote_port = remote_port
         self._state = 'new'
+        self._message = Message(Peer(remote_ip, remote_port))
         
         if (self._policy != None) and \
             (not self._policy.accept_new_connection(self.remote_ip_string, self.remote_port)):
         """This method handles not a real smtp command. It is called when a new
         connection was accepted by the server."""
         primary_hostname = self._session.primary_hostname
-        reply_text = '%s Hello %s' % (primary_hostname, self.remote_ip_string)
+        reply_text = '%s Hello %s' % (primary_hostname, self._message.peer.remote_ip)
         self.reply(220, reply_text)
-        self._message = Message(None)
     
     def smtp_quit(self):
         primary_hostname = self._session.primary_hostname
     
     def smtp_helo(self):
         helo_string = self._command_arguments
-        # We could store the helo string for a later check
+        self._message.smtp_helo = helo_string
         primary_hostname = self._session.primary_hostname
         self.reply(250, primary_hostname)
     

File tests/basic_message_sending_test.py

 
 from unittest import TestCase
 
-from pymta import SMTPProcessor
+from pymta import Peer, SMTPProcessor
+
 
 class MockSession(object):
     primary_hostname = 'localhost'
 class MockServer(object):
     def __init__(self):
         self.messages = []
-
     
     def new_message_received(self, msg):
         self.messages.append(msg)
 
 
+
 class BasicMessageSendingTest(TestCase):
 
     def setUp(self):
         
         self.assertEqual(1, len(self.server.messages))
         msg = self.server.messages[0]
+        self.assertEqual('127.0.0.1', msg.peer.remote_ip)
+        self.assertEqual(4567, msg.peer.remote_port)
+        
+        self.assertEqual('foo.example.com', msg.smtp_helo)
         self.assertEqual('foo@example.com', msg.smtp_from)
         self.assertEqual('bar@example.com', msg.smtp_to)
         self.assertEqual(rfc822_msg, msg.msg_data)
 
-        
-        
-        
-        
 
-
-