def message_dict(message):
    """Convert a Message instance to a dict which can be written to JSON."""
    msg_dict = dict()

    msg_dict['guid'] = message.guid
    msg_dict['text'] = message.text
    msg_dict['handle_id'] = message.handle_id
    msg_dict['date'] = message.date
    msg_dict['is_from_me'] = bool(message.is_from_me)

    if message.subject is not None:
        msg_dict['subject'] = message.subject

    if message.attachments:
        msg_dict['attachments'] = message.attachments

    return msg_dict