“Take every thought captive to the obedience of Christ” (2 Corinthians 10:5).
The sanctification of the mind is one of the keys to enjoying inward peace and for that reason it is opposed strenuously, particularly in this era dominated by visual media that intrudes upon our minds relentlessly. Therefore, knowing the mechanics of the workings and interaction between the heart the mind and the soul is important.
Man is a living soul (Genesis 2:7) and the mind is the gateway to the soul; what the mind allows itself to be occupied with finds its way into the soul. Now the mind itself is directed by the heart; if the heart is inclined towards God, the heart will direct the mind towards righteous and godly thoughts and, at the same time, direct it away from evil thoughts. But if the heart is not positively inclined towards God, if it is allowed to wander of its own accord, the mind will find itself being opened up towards thoughts of ungodliness and unrighteousness.
To combat this pernicious influence, ask God to post angels to guard the doorway into your heart, your mind and your soul, to stop evil spirits finding their way in when you are either asleep or your mind is resting.