Esempio n. 1
0
def api_set_settings() -> Response:
    request_data = request.get_json()

    accounts = request_data.get('accounts', [])

    try:
        validate_unique_accounts(accounts)
    except ValueError as e:
        abort(400, f'{e}')

    for account in accounts:
        # IMAP user/password accounts
        _extract_any_secret('account', 'password',
                            account.get('imap_connection'))
        _extract_any_secret('account', 'password',
                            account.get('smtp_connection'))
        # IMAP OAuth accounts
        _extract_any_secret('oauth-account', 'oauth_refresh_token',
                            account.get('imap_connection'))
        _extract_any_secret('oauth-account', 'oauth_refresh_token',
                            account.get('smtp_connection'))

    changed_keys = overwrite_settings(request_data)

    # If sync days changes we need to nuke the caches
    if 'system.sync_days' in changed_keys:
        bust_all_caches()  # nuke the on-disk caches

    reset_accounts()  # un-cache accounts + folders to pick up settings changes
    reload_main_window()

    return jsonify(saved=True)
Esempio n. 2
0
def api_activate_license() -> Union[Response, Tuple[Response, int]]:
    request_data = request.get_json()
    license_data = get_or_400(request_data, 'license')

    # Cleanup any copy/paste issues with the license
    license_data = license_data.strip()
    license_data = license_data.strip('-')
    license_data = license_data.strip()

    try:
        email, token = [line.strip() for line in license_data.splitlines()]
    except ValueError:
        return jsonify(
            activated=False,
            error_message=
            'Invalid license format, it should include both email and token.',
        ), 400

    try:
        activate_license(email, token)
    except LicenseActivationError as e:
        abort(400, f'{e}')

    reload_main_window()
    return jsonify(activated=True)
Esempio n. 3
0
def api_activate_license():
    request_data = request.get_json()
    license_data = get_or_400(request_data, 'license')

    try:
        email, token = [line.strip() for line in license_data.splitlines()]
    except ValueError:
        return jsonify(activated=False, error='Invalid license format!'), 400

    try:
        activate_license(email, token)
    except LicenseActivationError as e:
        abort(400, f'{e}')

    reload_main_window()
    return jsonify(activated=True)
Esempio n. 4
0
def api_set_settings() -> Response:
    request_data = request.get_json()

    accounts = request_data.get('accounts', [])
    validate_unique_accounts(accounts)

    for account in accounts:
        _extract_password(account.get('imap_settings'))
        _extract_password(account.get('smtp_settings'))

    changed_keys = overwrite_settings(request_data)

    # If sync days changes we need to nuke the caches
    if 'system.sync_days' in changed_keys:
        bust_all_caches()  # nuke the on-disk caches

    reset_accounts()  # un-cache accounts + folders to pick up settings changes
    reload_main_window()

    return jsonify(saved=True)
Esempio n. 5
0
def api_delete_license():
    remove_license()
    reload_main_window()
    return jsonify(deleted=True)
Esempio n. 6
0
def api_delete_caches() -> Response:
    bust_all_caches()
    reload_main_window()
    return jsonify(deleted=True)