mirror of
https://github.com/craigerl/aprsd.git
synced 2025-09-08 08:07:49 -04: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:
parent
cfb172481d
commit
030b02551f
@ -31,6 +31,7 @@ def _imap_connect():
|
|||||||
port=imap_port,
|
port=imap_port,
|
||||||
use_uid=True,
|
use_uid=True,
|
||||||
ssl=use_ssl,
|
ssl=use_ssl,
|
||||||
|
timeout=30,
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.error("Failed to connect IMAP server")
|
LOG.error("Failed to connect IMAP server")
|
||||||
@ -64,15 +65,27 @@ def _smtp_connect():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if use_ssl:
|
if use_ssl:
|
||||||
server = smtplib.SMTP_SSL(host=host, port=smtp_port)
|
server = smtplib.SMTP_SSL(
|
||||||
|
host=host,
|
||||||
|
port=smtp_port,
|
||||||
|
timeout=30,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
server = smtplib.SMTP(host=host, port=smtp_port)
|
server = smtplib.SMTP(
|
||||||
|
host=host,
|
||||||
|
port=smtp_port,
|
||||||
|
timeout=30,
|
||||||
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.error("Couldn't connect to SMTP Server")
|
LOG.error("Couldn't connect to SMTP Server")
|
||||||
return
|
return
|
||||||
|
|
||||||
LOG.debug("Connected to smtp host {}".format(msg))
|
LOG.debug("Connected to smtp host {}".format(msg))
|
||||||
|
|
||||||
|
debug = CONFIG["aprsd"]["email"]["smtp"].get("debug", False)
|
||||||
|
if debug:
|
||||||
|
server.set_debuglevel(5)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
server.login(
|
server.login(
|
||||||
CONFIG["aprsd"]["email"]["smtp"]["login"],
|
CONFIG["aprsd"]["email"]["smtp"]["login"],
|
||||||
@ -120,7 +133,7 @@ def validate_shortcuts(config):
|
|||||||
for key in delete_keys:
|
for key in delete_keys:
|
||||||
del config["aprsd"]["email"]["shortcuts"][key]
|
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):
|
def get_email_from_shortcut(addr):
|
||||||
|
@ -189,10 +189,21 @@ def setup_logging(config, loglevel, quiet):
|
|||||||
fh.setFormatter(log_formatter)
|
fh.setFormatter(log_formatter)
|
||||||
LOG.addHandler(fh)
|
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:
|
if not quiet:
|
||||||
sh = logging.StreamHandler(sys.stdout)
|
sh = logging.StreamHandler(sys.stdout)
|
||||||
sh.setFormatter(log_formatter)
|
sh.setFormatter(log_formatter)
|
||||||
LOG.addHandler(sh)
|
LOG.addHandler(sh)
|
||||||
|
if imap_logger:
|
||||||
|
imap_logger.addHandler(sh)
|
||||||
|
|
||||||
|
|
||||||
@main.command()
|
@main.command()
|
||||||
|
@ -46,6 +46,7 @@ DEFAULT_CONFIG_DICT = {
|
|||||||
"host": "smtp.gmail.com",
|
"host": "smtp.gmail.com",
|
||||||
"port": 465,
|
"port": 465,
|
||||||
"use_ssl": False,
|
"use_ssl": False,
|
||||||
|
"debug": False,
|
||||||
},
|
},
|
||||||
"imap": {
|
"imap": {
|
||||||
"login": "IMAP_USERNAME",
|
"login": "IMAP_USERNAME",
|
||||||
@ -53,6 +54,7 @@ DEFAULT_CONFIG_DICT = {
|
|||||||
"host": "imap.gmail.com",
|
"host": "imap.gmail.com",
|
||||||
"port": 993,
|
"port": 993,
|
||||||
"use_ssl": True,
|
"use_ssl": True,
|
||||||
|
"debug": False,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user