Skip to content

Commit

Permalink
feat: add imapserver script and argparse for host:port
Browse files Browse the repository at this point in the history
  • Loading branch information
bamthomas committed Jan 11, 2025
1 parent 0e48745 commit 42e18b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 17 additions & 3 deletions aioimaplib/tests/imapserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import asyncio
from base64 import b64decode
import email
Expand Down Expand Up @@ -795,11 +796,24 @@ def create(to, mail_from='', subject='', content='',
return Mail(msg, date=date)


async def main():
srv = await MockImapServer(loop=asyncio.get_running_loop()).run_server()
async def async_main(**kwargs):
log.info(f"Running IMAP server on {kwargs['host']}:{kwargs['port']}")
srv = await MockImapServer(loop=asyncio.get_running_loop()).run_server(host=kwargs['host'], port=kwargs['port'])
async with srv:
await srv.serve_forever()


def main():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog='imapserver',
description='Small python asyncio IMAP testing server.',
epilog='')
parser.add_argument('--port', help='tcp port of the server', default=1143)
parser.add_argument('--host', help='host of the server', default='127.0.0.1')
args = parser.parse_args()
asyncio.run(async_main(**args.__dict__))


if __name__ == '__main__':
asyncio.run(main())
main()
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ pytest-cov = "^6.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
imapserver = "aioimaplib.tests.imapserver:main"

0 comments on commit 42e18b8

Please sign in to comment.