The following is taken from  "HANDBOOK OF MORAL THEOLOGY"  by Dominic M. Prümmer, O.P. 1957

Art. 2. No. 539   The Attention and Intention of the Minister

of the Sacraments

539. I. ATTENTION. For the valid administration of the sacraments external attention is necessary and also sufficient; for their lawful administration there is required internal intention which excludes all voluntary distraction. Consequently the minister who confers a sacrament while willingly yielding to distraction does so validly but unlawfully. The sin is usually venial, but according to St. Alphonsus a priest who allows himself to be distracted during the consecration in Mass is guilty of such grave irreverence that he commits grave sin- this is not admitted by all theologians. 

540. 2. INTENTION is the reasoned direction of the will to some end through the use of certain means. So far as the sacraments are concerned, the intention ensures that the minister wills through means of the sacramental sign to do that which the Church does.

Kinds of intention.

a) From the subject's point of view the intention is either actual, virtual, habitual, or interpretative. An actual intention is one which is elicited here and now while the act is in progress. A virtual intention is one made on a previous occasion, never retracted, and still exerting its influence on the present human act of the minister. An habitual intention is one which although formed on a previous occasion and never retracted, yet has no positive influence on the act as a human act. An interpretative intention is one which never has existed, does not exist at present but is presumed to exist from clear indications; v.g. a dying Protestant who is unconscious and is known to have been in good faith and to have led an upright life is considered to possess an interpretative intention of receiving absolution and therefore may be absolved conditionally.

b) From the object's point of view, the intention may be either confused or clear according as the object intended is confusedly or clearly present to the mind; it is definite if his will is directed towards an object which is precise in every respect, it is indefinite if the object is only vaguely indicated; his intention is furthermore either explicit or implicit depending on whether the object which is clearly recognised is intended in itself or in something else to which it is conjoined. Finally, his intention is absolute or conditional according to whether the object is intended with or without conditions attached.

541. THE NECESSITY OF AN INTENTION. a) For the valid administration of the sacraments, the minister must have at least the intention of doing that which the Church does.

This is defined as being of faith in the Council of Trent (Sess. 7, C. 11 de sacr. in gen.). But theologians are not agreed regarding the exact meaning of that phrase- the intention of doing that which the Church does. Some are of the opinion that the only intention required in the minister is that he should have a serious will to apply the matter and the form (an external intention); others state as being the more correct opinion that such an intention is insufficient and that there is also required in the minister the will to perform the rite in so far as it is considered a sacred rite by the true Church (an internal intention), since the minister is bound to act as the minister of Christ. Therefore he must intend to perform a rite which is considered sacred by the Church of Christ. But it is not necessary that the minister himself believe the rite to be sacred. Similarly it is not required that he will to do that which the Catholic Church does, provided that he intends to do what the true Church of Christ does.

b) Neither an interpretative intention nor an habitual intention is sufficient; an actual intention is not demanded; a virtual intention is sufficient and must be present.