Skip to content

Commit

Permalink
Fix usage of nullsmtpd when not using fork
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin committed Mar 20, 2019
1 parent 73f29a4 commit c965a98
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions nullsmtpd/nullsmtpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
without spamming customers' emails and not having overhead from some GUI program.
"""
import argparse
import asyncio
import os
import time

Expand Down Expand Up @@ -88,7 +89,7 @@ def _parse_args():
"""
parser = argparse.ArgumentParser(description="")
parser.add_argument("--no-fork", action="store_true",
help="Don't fork and run nullsmtpd as a daemon. Additionally, this will"
help="Don't fork and run nullsmtpd as a daemon. Additionally, this will "
"print all log messages to stdout/stderr and all emails to stdout.")
parser.add_argument("-H", "--host", type=str, default="localhost",
help="Host to listen on (defaults to localhost)")
Expand Down Expand Up @@ -120,17 +121,26 @@ def main():
logger = configure_logging(args.mail_dir, output_messages)
mail_dir = args.mail_dir

logger.info("Starting nullsmtpd {:s} on {:s}:{:d}".format(__version__, host, port))
controller = Controller(NullSMTPDHandler(logger, mail_dir, output_messages), hostname=host,
port=port)
logger.info(
"Starting nullsmtpd {:s} on {:s}:{:d}".format(
__version__,
host,
port
)
)
loop = asyncio.get_event_loop()
nullsmtpd = NullSMTPDHandler(logger, mail_dir, output_messages)
controller = Controller(nullsmtpd, hostname=host, port=port)
controller.start()

try:
controller.start()
if output_messages:
input('nullsmtpd running. Press enter to stop server and exit.')
raise SystemExit
loop.run_forever()
except (KeyboardInterrupt):
pass
finally:
logger.info('Stopping nullsmtpd')
controller.stop()
loop.stop()


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion nullsmtpd/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"""

__author__ = 'Matthew Peveler'
__version__ = '0.4.1'
__version__ = '0.5.0'
__license__ = 'Unlicense (Public Domain)'

0 comments on commit c965a98

Please sign in to comment.