1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-03-08 12:28:55 -05:00

Enable debug logging for smtp and imap

Add the new config options for
aprsd:
  email:
    imap:
      debug: True

    smtp:
      debug: True
This commit is contained in:
Hemna 2021-01-25 16:15:27 -05:00
parent cfb172481d
commit 030b02551f
3 changed files with 29 additions and 3 deletions

View File

@ -31,6 +31,7 @@ def _imap_connect():
port=imap_port,
use_uid=True,
ssl=use_ssl,
timeout=30,
)
except Exception:
LOG.error("Failed to connect IMAP server")
@ -64,15 +65,27 @@ def _smtp_connect():
try:
if use_ssl:
server = smtplib.SMTP_SSL(host=host, port=smtp_port)
server = smtplib.SMTP_SSL(
host=host,
port=smtp_port,
timeout=30,
)
else:
server = smtplib.SMTP(host=host, port=smtp_port)
server = smtplib.SMTP(
host=host,
port=smtp_port,
timeout=30,
)
except Exception:
LOG.error("Couldn't connect to SMTP Server")
return
LOG.debug("Connected to smtp host {}".format(msg))
debug = CONFIG["aprsd"]["email"]["smtp"].get("debug", False)
if debug:
server.set_debuglevel(5)
try:
server.login(
CONFIG["aprsd"]["email"]["smtp"]["login"],
@ -120,7 +133,7 @@ def validate_shortcuts(config):
for key in delete_keys:
del config["aprsd"]["email"]["shortcuts"][key]
LOG.info("Available shortcuts: {}".format(config["shortcuts"]))
LOG.info("Available shortcuts: {}".format(config["aprsd"]["email"]["shortcuts"]))
def get_email_from_shortcut(addr):

View File

@ -189,10 +189,21 @@ def setup_logging(config, loglevel, quiet):
fh.setFormatter(log_formatter)
LOG.addHandler(fh)
imap_logger = None
if config["aprsd"]["email"].get("enabled", False) and config["aprsd"]["email"][
"imap"
].get("debug", False):
imap_logger = logging.getLogger("imapclient.imaplib")
imap_logger.setLevel(log_level)
imap_logger.addHandler(fh)
if not quiet:
sh = logging.StreamHandler(sys.stdout)
sh.setFormatter(log_formatter)
LOG.addHandler(sh)
if imap_logger:
imap_logger.addHandler(sh)
@main.command()

View File

@ -46,6 +46,7 @@ DEFAULT_CONFIG_DICT = {
"host": "smtp.gmail.com",
"port": 465,
"use_ssl": False,
"debug": False,
},
"imap": {
"login": "IMAP_USERNAME",
@ -53,6 +54,7 @@ DEFAULT_CONFIG_DICT = {
"host": "imap.gmail.com",
"port": 993,
"use_ssl": True,
"debug": False,
},
},
},