import re
import html


def parse_message_msg(orig_msg):
    """
    Parse "message" message received from backend
    """

    orig_msg = orig_msg[9:]
    part = orig_msg.split(" ")
    acc = part[0]
    acc_name = part[1]
    tstamp = part[2]
    sender = part[3]
    msg = " ".join(part[4:])
    msg = "\n".join(re.split("<br/>", msg, flags=re.IGNORECASE))
    msg = html.unescape(msg)

    return "message", acc, acc_name, int(tstamp), sender, msg