'Exercise the methods of L{IMailbox} as implemented by
L{MaildirMailbox}.'

def test_mailbox(self):

    j = os.path.join
    n = mail.maildir._generateMaildirName
    msgs = [j(b, n()) for b in ('cur', 'new') for x in range(5)]
    i = 1
    for f in msgs:
        with open(j(self.d, f), 'w') as fObj:
            fObj.write(('x' * i))
        i = (i + 1)
    mb = mail.maildir.MaildirMailbox(self.d)
    self.assertEqual(mb.listMessages(), list(range(1, 11)))
    self.assertEqual(mb.listMessages(1), 2)
    self.assertEqual(mb.listMessages(5), 6)
    self.assertEqual(mb.getMessage(6).read(), ('x' * 7))
    self.assertEqual(mb.getMessage(1).read(), ('x' * 2))
    d = {}
    for i in range(10):
        u = mb.getUidl(i)
        self.assertFalse((u in d))
        d[u] = None
    (p, f) = os.path.split(msgs[5])
    mb.deleteMessage(5)
    self.assertEqual(mb.listMessages(5), 0)
    self.assertTrue(os.path.exists(j(self.d, '.Trash', 'cur', f)))
    self.assertFalse(os.path.exists(j(self.d, msgs[5])))
    mb.undeleteMessages()
    self.assertEqual(mb.listMessages(5), 6)
    self.assertFalse(os.path.exists(j(self.d, '.Trash', 'cur', f)))
    self.assertTrue(os.path.exists(j(self.d, msgs[5])))
