from Understanding the Tanya (translator).

CHAPTER 27
In the previous chapter, the author asserted that we must struggle to overcome depression and extirpate it from our hearts, irrespective of its cause—whether mundane or spiritual (with a few specific exceptions, in which we utilize sadness as a vehicle to transport us to authentic joy in our service of God).
This chapter continues the discussion of various types of depression—including that which seems to have its roots in holiness—and offers advice on how to deal with pernicious thoughts and desires.
Should the sadness, however, not come from worry over sins, but from evil thoughts and desires that enter his mind--
Earlier, the author stated that depression caused by dwelling on one’s sins does not play a role in the service of God and is, to the contrary, entirely disadvantageous. Here he adds that this applies not only to reflecting on the past but also to reacting to negative thoughts and desires of the moment.
Every individual engaged in serving God must sooner or later encounter the universal and fundamental problem that nothing in our spiritual growth is assured.Even after we have dedicated our lives to holiness and engaged only in sanctified deeds, words and thoughts, we may be suddenly assailed by doubts in our faith and profane desires.
Were a person to judge his life at such a moment, he might well deem it a hopeless failure. He might question what his service of God had accomplished and whether he had at all grown spiritually. At such a moment, he is liable to experience a melancholy more deleterious than any sin he has ever committed.
If they--
If spiritual doubts and harmful desires--
enter not during Divine Service--
But when a person is not engaged in learning Torah, performing mitzvot or praying--
But whilst he is occupied with his own affairs and with mundane matters and the like--
Such as earning a living or eating and drinking--
He should, on the contrary, be happy in his portion.
Rather than growing despondent that he experienced such thoughts, he should experience joy.
In that, though they enter his mind, he averts his mind from them[1] in order to fulfill the injunction, “That ye seek not after your own heart and your own eyes, after which ye go astray” (Numbers 15:39). The verse does not speak of the righteous, to refer to them as “going astray,” God forbid.
Clearly, the phrase “after which ye go astray” is not speaking of tzaddikim, who do not experience temptation in their daily lives.
But of “Intermediates” (benonim) like him, in whose mind do enter erotic thoughts, whether of an innocent nature—
An erotic thought of an innocent nature involves someone with whom relations are permitted—e.g., one’s spouse.
And so on--
And forbidden relations.
When he averts his mind from them, he is fulfilling this injunction.
Even if a person does not succeed in fully averting his mind but at least reduces the time or intensity of the thought, he fulfills a negative commandment.[2]
Indeed, the Rabbis, of blessed memory, have said, “He who has passively abstained from committing a sin, receives a reward as though he had performed a precept” (Kiddushin 39b). Consequently, he should rejoice at his compliance with the injunction as when performing an actual positive precept.
The Talmud teaches that a person fulfills this negative commandment when he refrains from acting [translator’s words: or dwelling] on a thought that has entered his mind. That being the case, why should he grow depressed? He has performed an act no less important than any other mitzvah.
The author now discusses this topic in greater detail.
On the contrary, such sadness—
Which comes from the fact that one has experienced negative thoughts--
is due to conceit.
A person may think that his despondency is an expression of holiness. However, it actually comes from the kelipah of overweening pride. He feels proud--
In that he does not recognize his position—
And so he appraises himself too highly.
Hence he is sad at heart because he has not attained the rank of a tzaddik, inasmuch as the righteous are certainly not troubled by such foolish thoughts.
Since he considers himself a tzaddik, he grows dispirited when he experiences such thoughts. This mood originates not in holiness but in egotism.
He may also grow angry that others do not recognize him as a tzaddik. And, feeling insulted that he must still struggle, he may lash out as he wonders why, having already gained spiritual victory, he is fated to repeat his travails--
For had he recognized his station, that he is very far from the rank of a tzaddik--
A rank that is extraordinarily high, one attained by an elite few in each generation, and which no one else—not even those who have served God in a spirit of holiness for the entirety of their lives—can realistically strive to achieve--
And would that he be a benoni and not a wicked person even for a single moment throughout his life.
A person must strive to be a benoni. When he sets this as his goal, he will not grow upset or disheartened should he experience evil urges and foolish thoughts.
Then surely, this is the quality of the “Intermediates” and their service: To subdue the evil impulse and thought that rises from the heart to the brain, and completely to avert the mind therefrom, thrusting the temptation away with both hands, as has been explained earlier.
A benoni has not solved any problems at their root; he has not transformed his character in any fundamental sense. He continues to possess the inclinations, desires and weaknesses of his past. There is a difference, however, between him and a wicked person, for now he has the ability to control these qualities.
Nevertheless, he has not yet concluded the battle, but remains in the midst of the fray, struggling to repulse the many temptations that assail him.
And with every thrust wherewith he expels it from his mind—
The benoni lacks the ability to control his heart—his power rests in his thought. Thus, when temptation rises to his mind and changes from desire to thought, he can repel it, so as neither to consider nor commit the deed.
And when he pushes away this temptation, when--
The sitra achra down below is suppressed.
He subjugates the sitra achra, the force of impurity as it exists on our plane--
And, since the “Stimulus from below causes a stimulus from above”--
Whatever occurs in this world occurs as well in the upper world, in an even more powerful and encompassing manner.
When the sitra achra is subdued in this world, then
the sitra achra above--
At its source--
Which soars like an eagle--
The root of the existence of the kelipah is that it elevates itself to become an independent entity separate from God-
Is also suppressed.
This root of impurity—
In accordance with Scripture, “Though thou exalt thyself as the eagle, thence I will bring thee down, saith the Lord” (Obadiah 1:4). Thus the Zohar, Parshat Terumah (p. 128), extols the great satisfaction before Him, blessed be He, when the sitra achra is subdued here below, for then the glory of the Holy One, blessed be He, rises above all,more than by any praise, and this ascent its greater than all else, and so forth.
The subjugation of evil manifests God’s praise, for He is then glorified in all the worlds. This is the greatest encomium possible, expressing the fulfillment of the inner purpose of the creation of all universes—the ultimate goal for whose sake the entire awesome and complex structure of reality is necessary.
The divine service of an angel is more elevated and perfect than anything that a human being could accomplish. However, since an angel exists solely in the upper worlds, it does not utilize the entirety of all being. As such, an angel does not fulfill the supernal intent of the totality of creation. Only lowly and imperfect man, who struggles with himself, who is liable to capitulate to the sitra achra and descend to the depths of degradation, causes God’s glory to rise beyond all other praise, to the ultimate and primal point of all existence and beyond, when he subdues the sitra achra.
[1] Even if he did not avert his attention, that was only because he was engaged in [translator’s words: the mitzvah of] “worrying over one’s sins,” which the author has discussed above—note of R. Menachem Mendel Schneerson.
[2] See Maimonides’ Sefer Hamitzvot, Prohibition 47.