Ibn Qayyim al Jawziyyah (d.751H) said:
Unnecessary companionship is a chronic disease that causes much harm. How often have the wrong kind of companionship and intermixing deprived people of Allah’s generosity, planting discord in their hearts which even the passage of time-even if it were long enough for mountains to be worn away-has been unable to dispel. In keeping such company one can find the roots of loss, both in this life and in the next life.
A servant should benefit from companionship. In order to do so he should divide people into four categories, and be careful not to get them mixed up, for once one of them is mixed with another, then evil can find its way through to him:
The first category are those people whose company is like food: it is indispensable, night or day. Once a servant has taken his need from it, he leaves it be until he requires it again, and so on. These are the people with knowledge of Allah – of His commands, of the scheming of His enemies, and of the diseases of the heart and their remedies – who wish well for Allah, His Prophet and His servants. Associating with this type of person is an achievement in itself.
The second category are those people whose company is like a medicine. They are only required when a disease sets in. When you are healthy, you have no need of them. However, mixing with them is sometimes necessary for your livelihood, businesses, consultation and the like. Once what you need from them has been fulfilled, mixing with them should be avoided.
The third category are those people whose company is harmful. Mixing with this type of person is like a disease, in all its variety and degrees and strengths and weaknesses. Associating with one or some of them is like an incurable chronic disease. You will never profit either in this life or in the next life if you have them for company, and you will surely lose either one or both of your deen and your livelihood because of them. If their companionship has taken hold of you and is established, then it becomes a fatal, terrifying sickness.
Amongst such people are those who neither speak any good that might benefit you, nor listen closely to you so that they might benefit from you. They do not know their souls and consequently put their selves in their rightful place. If they speak, their words fall on their listeners’ hearts like the lashes of a cane, while all the while they are full of admiration for and delight in their own words.
They cause distress to those in their company, while believing that they are the sweet scent of the gathering. If they are silent, they are heavier than a massive millstone-too heavy to carry or even drag across the floor 
All in all, mixing with anyone who is bad for the soul will not last, even if it is unavoidable. It can be one of the most distressing aspects of a servant’s life that he is plagued by such person, with whom it may be necessary to associate. In such a relationship, a servant should cling to good behaviour, only presenting him with his outward appearance, while disguising his inner soul, until Allah offers him a way out of his affliction and the means of escape from this situation.
The fourth category are those people whose company is doom itself. It is like taking poison: its victim either finds an antidote or perishes. Many people belong to this category. They are the people of religious innovation and misguidance, those who abandon the sunnah of the Messenger of Allah and advocate other beliefs. They call what is the sunnah a bid’a and vice-versa. A man with any intellect should not sit in their assemblies nor mix with them. The result of doing so will either be the death of his heart or, at the very best, its falling seriously ill.
What Gives the Heart Life and Sustenance
You should know that acts of obedience are essential to the well being of the servant’s heart, just in the same way that food and drink are to that of the body. All wrong actions are the same as poisonous foods, and they inevitably harm the heart.
The servant feels the need to worship his Lord, Mighty and Glorious is He, for he is naturally in constant need of His help and assistance.
In order to maintain the well being of his body, the servant carefully follows a strict diet. He habitually and constantly eats good food at regular intervals, and is quick to free his stomach of harmful elements if he happens to eat bad food by mistake.
The well being of the servant’s heart, however, is far more important than that of his body, for while the well being of his body enables him to lead a life that is free from illnesses in this world, that of the heart ensures him both a fortunate life in this world and eternal bliss in the next.
In the same way, while the death of the body cuts the servant off from this world, the death of the heart results in everlasting anguish. A righteous man once said, “How odd, that some people mourn for the one whose body has died, but never mourn for the one whose heart has died and yet the death of the heart is far more serious!”
Thus acts of obedience are indispensable to the well being of the heart. It is worthwhile mentioning the following acts of obedience here, since they are very necessary and essential for the servant’s heart: Dhikr of Allah ta’Ala, recitation of the Noble Qur’an, seeking Allah’s forgiveness, making du’as, invoking Allah’s blessings and peace on the Prophet, may Allah bless him and grant him peace, and praying at night.
From the book, Purification of the Soul.
 Ash-Shafi`ee, may Allah be pleased with him, is reported to have said, “Whenever a tedious person sits next to me, the side on which he is sitting feels lower down than the other side of me.”