Ticket #4623: 4623.patch

File 4623.patch, 4.3 KB (added by moijes12, 7 years ago)

Used pepijn's patch, Glyph's comments and some time to create this patch. I was not so sure how to create the unit test and how to name it. Suggestions for improvements would be welcome.

  • twisted/mail/test/test_mail.py

     
    1515import signal
    1616
    1717from zope.interface import Interface, implements
     18from zope.interface.verify import verifyClass
    1819
    1920from twisted.trial import unittest
    2021from twisted.mail import smtp
     
    20542055
    20552056
    20562057
     2058class QueueInterfaceTest(unittest.TestCase):
     2059    """
     2060    Test for interface of class twisted.mail.relaymanager.Queue.
     2061    """
     2062
     2063
     2064    def test_QueueInterface(self):
     2065        """
     2066        Verift that L{Queue} implements L{IQueue}.
     2067        """
     2068        self.assertTrue(verifyClass(twisted.mail.relaymanager.IQueue, twisted.mail.relaymanager.Queue))
     2069
     2070
     2071
    20572072from twisted.python.runtime import platformType
    20582073import types
    20592074if platformType != "posix":
  • twisted/mail/relaymanager.py

     
    3939from twisted.mail import smtp
    4040from twisted.application import internet
    4141
     42from zope.interface import Interface, implements
     43
    4244class ManagedRelayerMixin:
    4345    """SMTP Relayer which notifies a manager
    4446
     
    131133        protocol.factory = self
    132134        return protocol
    133135
     136
     137
     138class IQueue(Interface):
     139    """
     140    A queue of messages.
     141    """
     142   
     143
     144    def createNewMessage():
     145        """
     146        Create a new message in the queue.
     147
     148        @return: A tuple containing the message header and a file-like object containing references to the message file.
     149        @rtype:  C{tuple}
     150        """
     151
     152
     153    def readDirectory():
     154        """
     155        Look for new messages in the messages directory adding them to queue of messages waiting to be relayed.
     156
     157        @return: None.
     158        @rtype:  None
     159        """
     160
     161
     162    def getPath(message):
     163        """
     164        Get the filesystem path of the given message.
     165
     166        @type message: C{str}
     167        param message: Message for which the filesystem path of the file object is required
     168        @return: a string representing the filesystem path where the message is stored.
     169        @rtype:  C{str}
     170        """
     171
     172
     173    def hasWaiting():
     174        """
     175        Check if there are any messages to be relayed.
     176
     177        @return: a boolean value which is True if there are any messages waiting to be transferred and false if there are no messages waiting to be transferred.
     178        @rtype:  C{bool}
     179        """     
     180
     181
     182    def getWaiting():
     183        """
     184        Return a list of messages waiting to be relayed.
     185
     186        @return: a list of messages waiting in the queue to be relayed.
     187        @rtype:  C{list}
     188        """
     189
     190
     191    def setWaiting(message):
     192        """
     193        Add a message to the queue of messages waiting to be relayed.
     194
     195        @type message: C{str}
     196        @param message: Message to be added to the queue of messages waiting to be relayed.
     197        """
     198
     199
     200    def getRelayed():
     201        """
     202        Get the list of relayed messages.
     203
     204        @return: a list of messages relayed by the system.
     205        @rtype:  C{list}
     206        """
     207 
     208
     209    def setRelaying(message):
     210        """
     211        Add a message from the waiting queue to the queue of messages to be relayed.
     212
     213        @type message: C{str}
     214        @param message: Message to be added to the queue of messages to be relayed.
     215        """
     216
     217
     218    def getEnvelope(message):
     219        """
     220        Get a message file object for the given message.
     221
     222        @type message: C{str}
     223        @param message: Message for which the file object is to be obtained.
     224
     225        @return: Message file object for the message.
     226        @rtype:  C{object}
     227        """
     228
     229 
     230    def getEnvelopeFile(message):
     231        """
     232        Get the file handle to the message file object of a given message.
     233
     234        @type message: C{str}
     235        @param message: The message for which the file handle to its message file object is to be obtained.
     236
     237        @return: File handle of the message file object of message.
     238        @rtype: C{object}
     239        """
     240
     241
     242
    134243class Queue:
    135244    """A queue of ougoing emails."""
    136245
     246    implements(IQueue)
     247
    137248    noisy = True
    138249
    139250    def __init__(self, directory):