Ticket #4623: 4623.3.patch

File 4623.3.patch, 5.6 KB (added by moijes12, 7 years ago)
  • twisted/mail/relaymanager.py

     
    2828except ImportError:
    2929    import pickle
    3030
     31from zope.interface import Interface, implements
     32
    3133from twisted.python import log
    3234from twisted.python.failure import Failure
    3335from twisted.python.compat import set
     
    131133        protocol.factory = self
    132134        return protocol
    133135
     136class IRelayQueue(Interface):
     137    """
     138    A queue of mail messages to be relayed.
     139    """
     140
     141
     142    def createNewMessage():
     143        """
     144        Create a new message in the queue.
     145
     146        @return: A tuple containing the message header and a file-like object containing references to the message file.
     147        @rtype:  C{tuple}
     148        """
     149
     150
     151    def readDirectory():
     152        """
     153        Look for new messages in the messages directory adding them to queue of messages waiting to be relayed.
     154
     155        @return: C{None}
     156        @rtype:  C{NoneType}
     157        """
     158
     159
     160    def done(message):
     161        """
     162        Remove message from the queue and delete it from the file system.
     163
     164        @param message: Message to be removed.
     165        @type message: C{str}
     166
     167        @return: C{None}
     168        @rtype:  C{NoneType}
     169        """
     170
     171
     172    def getPath(message):
     173        """
     174        Get the filesystem path of the given message.
     175
     176        @param message: Message for which the filesystem path of the file object is required
     177        @type message: C{str}
     178
     179        @return: a string representing the filesystem path where the message is stored.
     180        @rtype:  C{str}
     181        """
     182
     183
     184    def hasWaiting():
     185        """
     186        Check if there are any messages to be relayed.
     187
     188        @return: a boolean value which is C{True} if there are any messages waiting to be transferred and C{False} if there are no messages waiting to be transferred.
     189        @rtype:  C{bool}
     190        """
     191
     192
     193    def getWaiting():
     194        """
     195        Return a list of messages waiting to be relayed.
     196
     197        @return: a list of messages waiting in the queue to be relayed.
     198        @rtype:  C{list}
     199        """
     200
     201
     202    def setWaiting(message):
     203        """
     204        Add a message to the queue of messages waiting to be relayed.
     205
     206        @param message: Message to be added to the queue of messages waiting to be relayed.
     207        @type message: C{str}
     208
     209        @return: C{None}
     210        @rtype:  C{NoneType}
     211        """
     212
     213
     214    def addMessage(message):
     215        """
     216        Add a message to the queue of messages waiting to be relayed if and only if it has not already been relayed.
     217
     218        @param message: Message to be added to the queue of messages waiting to be relayed.
     219        @type message: C{str}
     220
     221        @return: C{None}
     222        @rtype:  C{NoneType}
     223        """
     224
     225
     226    def setRelaying(message):
     227        """
     228        Add a message from the waiting queue to the queue of messages to be relayed.
     229
     230        @param message: Message to be added to the queue of messages to be relayed.
     231        @type message: C{str}
     232
     233        @return: C{None}
     234        @rtype:  C{NoneType}
     235        """
     236
     237
     238    def getEnvelope(message):
     239        """
     240        Get a message file object for the given message.
     241
     242        @type message: C{str}
     243        @param message: Message for which the file object is to be obtained.
     244
     245        @return: Message file object for the message.
     246        @rtype:  C{object}
     247        """
     248
     249 
     250    def getEnvelopeFile(message):
     251        """
     252        Get the file handle to the message file object of a given message.
     253
     254        @type message: C{str}
     255        @param message: The message for which the file handle to its message file object is to be obtained.
     256
     257        @return: File handle of the message file object of message.
     258        @rtype: C{file}
     259        """
     260
     261
     262
    134263class Queue:
    135264    """A queue of ougoing emails."""
    136265
     266    implements(IRelayQueue)
     267
    137268    noisy = True
    138269
    139270    def __init__(self, directory):
     
    341472
    342473    def __init__(self, queue, maxConnections=2, maxMessagesPerConnection=10):
    343474        """
    344         @type queue: Any implementor of C{IQueue}
     475        @type queue: Any implementor of C{IRelayQueue}
    345476        @param queue: The object used to queue messages on their way to
    346477        delivery.
    347478
  • twisted/mail/test/test_mail.py

     
    1515import signal
    1616
    1717from zope.interface import Interface, implements
     18from zope.interface.verify import verifyObject
    1819
    1920from twisted.trial import unittest
    2021from twisted.mail import smtp
     
    5152
    5253from twisted.test.proto_helpers import LineSendingProtocol
    5354
     55from twisted.mail.relaymanager import IRelayQueue
    5456class DomainWithDefaultsTestCase(unittest.TestCase):
    5557    def testMethods(self):
    5658        d = dict([(x, x + 10) for x in range(10)])
     
    10021004                ['header', i]
    10031005            )
    10041006
     1007
     1008    def test_queueInterface(self):
     1009        """
     1010        Verify that L{Queue} implements L{IRelayQueue}.
     1011        """
     1012        self.assertTrue(verifyObject(IRelayQueue, self.queue))
     1013
     1014
    10051015from twisted.names import server
    10061016from twisted.names import client
    10071017from twisted.names import common
  • twisted/mail/topfiles/4623.bugfix

     
     1twisted.mail.relaymanager.IRelayQueue has been documented.