def split_msg(msgs, max_len):
    """Splits as close to the end as possible."""
    msg = ''
    while len(msg.encode()) < max_len:
        if len(msg.encode()) + len(msgs[0]) > max_len:
            return msg, msgs
        char = msgs.pop(0).decode()
        if char == ' ' and len(msg.encode()) > max_len - 15:
            return msg, msgs
        msg += char
    return msg, msgs
