Savemsg: saving messages in the db

Messages are now saved and can be recovered in multiple ways, also survive the process, server, whatever being restarted.

Should lead to lots of other good things in terms of functionality.

Also contains some minor re-structuring of code such as lib/util.js where I plan to put some good stuff to keep everything dry and robust