(account, folder, uid, part_number)
return jsonify(saved=True, filename=local_filename)
Download a specific part of an email by account/folder/UID.
Download a specific part of an email by account/folder/UID.
Download a specific part of an email by account / folder / UID .
def api_download_account_email_part(account, folder, uid, part_number) -> Response:
    '''
    Download a specific part of an email by account/folder/UID.
    '''

    downloads_folder = path.expanduser(path.join('~', 'Downloads'))
    local_filename = path.join(downloads_folder, path.basename(request.args['filename']))

    if path.exists(local_filename):
        extension = None
        if '.' in local_filename:
            local_filename, extension = local_filename.rsplit('.', 1)

        local_filename = f'{local_filename}-1'

        if extension:
            local_filename = f'{local_filename}.{extension}'

    mime_type, data = get_folder_email_part(
        account, folder, uid, part_number,
    )

    if mime_type is None:
        response = jsonify(error=f'Could not find part: {part_number}')
        response.status_code = 404
        return response

    if isinstance(data, str):
        data = data.encode()

    with open(local_filename, 'wb') as f:
        f.write(data)

    return jsonify(saved=True, filename=local_filename)
def api_download_account_email_part ( account , folder , uid , part_number ) -> Response : downloads_folder = path . expanduser ( path . join ( '~' , 'Downloads' ) ) local_filename = path . join ( downloads_folder , path . basename ( request . args [ 'filename' ] ) ) if path . exists ( local_filename ) : extension = None if '.' in local_filename : local_filename , extension = local_filename . rsplit ( '.' , 1 ) local_filename = f'{local_filename}-1' if extension : local_filename = f'{local_filename}.{extension}' mime_type , data = get_folder_email_part ( account , folder , uid , part_number , ) if mime_type is None : response = jsonify ( error = f'Could not find part: {part_number}' ) response . status_code = 404 return response if isinstance ( data , str ) : data = data . encode ( ) with open ( local_filename , 'wb' ) as f : f . write ( data ) return jsonify ( saved = True , filename = local_filename )