def message_charset(msg):
    """Return an email.message.Message's charset."""
    if msg.get_charset():
        return msg.get_charset()

    for key, val in msg.get_params():
        if key == 'charset':
            return val

    raise ValueError("Can't get charset from msg")