Fix SQL queries

I still need to figure out, what should happen when the account gets
removed and add an option to count unread messages only from current
account.