migrate some delete.php code to message.php

Also fix issue with deleting messages with a prepended ID