From bec2918f7c145addcaf11d352fdc583c87693b99 Mon Sep 17 00:00:00 2001 From: moralmunky Date: Sun, 22 Mar 2020 00:37:55 -0400 Subject: [PATCH] Added period split for email folders Try to split with / then with . otherwise just use INBOX --- .../mail_and_packages/config_flow.py | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/custom_components/mail_and_packages/config_flow.py b/custom_components/mail_and_packages/config_flow.py index cbbc4faf..5cfc0b85 100644 --- a/custom_components/mail_and_packages/config_flow.py +++ b/custom_components/mail_and_packages/config_flow.py @@ -122,11 +122,17 @@ async def _show_config_2(self, user_input): _LOGGER.error("Error listing mailboxes ... using default") mailboxes.append(DEFAULT_FOLDER) else: - for i in folderlist: - mailboxes.append(i.decode().split(' "/" ')[1].strip('"')) - #comment the two lines before and uncomment line after - #if line 126 is giving error - #mailboxes.append(DEFAULT_FOLDER) + try: + for i in folderlist: + mailboxes.append(i.decode().split(' "/" ')[1].strip('"')) + except IndexError: + _LOGGER.error("Error creating folder array trying period") + try: + for i in folderlist: + mailboxes.append(i.decode().split(' "." ')[1].strip('"')) + except IndexError: + _LOGGER.error("Error creating folder array, using INBOX") + mailboxes.append(DEFAULT_FOLDER) if user_input is not None: if "folder" in user_input: @@ -256,11 +262,17 @@ async def _show_step_options_2(self, user_input): _LOGGER.error("Error listing mailboxes ... using default") mailboxes.append(DEFAULT_FOLDER) else: - for i in folderlist: - mailboxes.append(i.decode().split(' "/" ')[1].strip('"')) - #comment the two lines before and uncomment line after - #if line 258 is giving error - #mailboxes.append(DEFAULT_FOLDER) + try: + for i in folderlist: + mailboxes.append(i.decode().split(' "/" ')[1].strip('"')) + except IndexError: + _LOGGER.error("Error creating folder array trying period") + try: + for i in folderlist: + mailboxes.append(i.decode().split(' "." ')[1].strip('"')) + except IndexError: + _LOGGER.error("Error creating folder array, using INBOX") + mailboxes.append(DEFAULT_FOLDER) if user_input is not None: if "folder" in user_input: