Skip to content

Commit

Permalink
update _test_login function
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 committed Jun 19, 2024
1 parent 3d1f288 commit 1c68541
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions custom_components/mail_and_packages/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,20 @@ async def _check_ffmpeg() -> bool:
return which("ffmpeg")


async def _test_login(host: str, port: int, user: str, pwd: str) -> bool:
async def _test_login(host: str, port: int, user: str, pwd: str, verify: bool) -> bool:
"""Test IMAP login to specified server.
Returns success boolean
"""
# Attempt to catch invalid mail server hosts
context = ssl.create_default_context()
if not verify:
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
else:
context = ssl.create_default_context(purpose=Purpose.SERVER_AUTH)
# Catch invalid mail server / host names
try:
account = imaplib.IMAP4_SSL(host, port)
account = imaplib.IMAP4_SSL(host=host, port=port, ssl_context=context)
except Exception as err:
_LOGGER.error("Error connecting into IMAP Server: %s", str(err))
return False
Expand Down

0 comments on commit 1c68541

Please sign in to comment.