'Change the behavior of future C{rename}, C{write}, or C{open} calls made
by the mailbox C{mbox}.
@param rename: If not L{None}, a new value for the C{_renamestate}
attribute of the mailbox\'s append factory.  The original value will
be restored at the end of the test.
@param write: Like C{rename}, but for the C{_writestate} attribute.
@param open: Like C{rename}, but for the C{_openstate} attribute.'

def _setState(self, ignored, mbox, rename=None, write=None, open=None):

    if (rename is not None):
        self.addCleanup(setattr, mbox.AppendFactory, '_renamestate', mbox.AppendFactory._renamestate)
        mbox.AppendFactory._renamestate = rename
    if (write is not None):
        self.addCleanup(setattr, mbox.AppendFactory, '_writestate', mbox.AppendFactory._writestate)
        mbox.AppendFactory._writestate = write
    if (open is not None):
        self.addCleanup(setattr, mbox.AppendFactory, '_openstate', mbox.AppendFactory._openstate)
        mbox.AppendFactory._openstate = open
