import email


def download_messages(server, messages_ids):
    """Downloads and returns messages as email.Message"""
    messages = {}
    for id, message_data in server.fetch(messages_ids, "RFC822").items():
        messages[id] = email.message_from_bytes(message_data[b"RFC822"])

    return messages