Function to extract the first part of a multipart message

def extract_first_part(message, boundary):
    """ Function to extract the first part of a multipart message"""
    first_message = message.split(boundary)[1].lstrip()
    if first_message.endswith(b'\r\n'):
        first_message = first_message[:-2]
    else:
        first_message = first_message[:-1]
    return first_message