Example #1
0
def connect_all():
    def make_account(key, settings):
        return key, Account(key, settings)

    with GET_ACCOUNTS_LOCK:
        ACCOUNTS.update(
            execute_threaded(make_account,
                             [(settings['name'], settings)
                              for settings in get_settings()['accounts']
                              if settings['name'] not in ACCOUNTS]))
Example #2
0
def remove_stale_folders():
    settings = get_settings()
    accounts = settings['accounts']
    account_names = set()
    for account in accounts:
        account_names.add(_make_account_key(account))

    deleted = 0
    all_folders = FolderCacheItem.query.all()

    for folder in all_folders:
        if folder.account_name not in account_names:
            logger.info(f'Deleting stale cache folder: {folder}')
            delete_cache_items(folder)
            deleted += 1

    logger.info(f'Deleted {deleted}/{len(all_folders)} cache folders')
Example #3
0
def api_get_settings() -> Response:
    settings = get_settings()

    account_name_to_connected = {}

    for account in settings.get('accounts', []):
        host = account['imap_connection']['host']
        username = account['imap_connection']['username']

        if account['imap_connection'].get('oauth_provider'):
            has_password = get_password('oauth-account', host,
                                        username) is not None
        else:
            has_password = get_password('account', host, username) is not None

        account_name_to_connected[account['name']] = has_password

    return jsonify(
        settings=settings,
        account_name_to_connected=account_name_to_connected,
        settings_file=SETTINGS_FILE,
    )
Example #4
0
def api_get_settings() -> Response:
    return jsonify(
        settings=get_settings(),
        settings_file=SETTINGS_FILE,
    )