def disconnect_lifelines(line, send, received):
    """
    Disconnect lifeline and set appropriate kind of message item. If
    there are no lifelines connected on both ends, then remove the message
    from the data model.
    """
    if not line.subject:
        return
    if send:
        event = line.subject.receiveEvent
        if event:
            event.unlink()
    if received:
        event = line.subject.sendEvent
        if event:
            event.unlink()
    if not send or not received:
        message = line.subject
        del line.subject
        if not message.presentation:
            message.unlink()
