Search code examples
pythontestingimapmocking

How do I mock an IMAP server in Python, despite extreme laziness?


I'm curious to know if there is an easy way to mock an IMAP server (a la the imaplib module) in Python, without doing a lot of work.

Is there a pre-existing solution? Ideally I could connect to the existing IMAP server, do a dump, and have the mock server run off the real mailbox/email structure.

Some background into the laziness: I have a nasty feeling that this small script I'm writing will grow over time and would like to create a proper testing environment, but given that it might not grow over time, I don't want to do much work to get the mock server running.


Solution

  • I found it quite easy to write an IMAP server in twisted last time I tried. It comes with support for writing IMAP servers and you have a huge amount of flexibility.