get categories from message and count messages in each categories