Mother's life in dangerHowever, what if the life of the mother is also in danger? Is abortion permitted then? In a lay person's terms, the church permits abortion only if the life of the mother is in danger. The reality is that the rules are a bit more nuanced.
If the mother's life is in danger and if a treatment for the ailment indirectly results in an abortion (or miscarriage), then it is called an indirect abortion. And this is permitted. The principle of double effect is in play here. 
If the treatment itself is aborting the fetus, then it is a direct abortion. Direct abortions are not permitted. Such abortions are morally evil, in the church's eyes, even when such an abortion could potentially save the mother's life!
Now, if such is the case when the life of the mother is in danger, then abortion in cases of rape, incest etc. are always morally evil. The Church's penalty of abortion is excommunication. 
This tap dance around the rules provides a possible solution which could save the mother's life!
In the case of a regular pregnancy, but one where the mother has uterine cancer as well, the uterus might be surgically removed and the baby aborted as a result. The abortion is indirect and hence acceptable. 
The SoulThe church's stand has two aspects. One is the morality (or the lack thereof) of killing a fetus. The other is that, the church these days teaches that a fetus gets a soul (ensoulment) right at the time of conception. This makes the fetus a human being in the eyes of the church. And since killing a human being is a grave moral sin, so is abortion.
HistoryThe church's stand on ensoulment and abortion has an interesting history. The church like to pretend that its teachings have always been consistent and constant since the foundation of the religion. Reality though, is never that neat, is it?
While the church has in general disapproved of abortion and considered it a sin, its thought on when exactly the ensoulment happened has varied. St. Augustine (354 - 430 AD) in "On Exodus" wrote that ensoulment happened much after conception. St. Thomas Aquinas (1225 - 1274) taught that ensoulment happened 40 to 80 days after conception for boys and girls respec.
Pope Innocent III (1161-1216) designated quickening as the time of ensoulment. Quickening is when the mother can feel the movement of the fetus and this is around 15 - 17 weeks.
In 1588, Pope Sixtus V in his Bull Effraenatam made abortion at any stage, an excommunicable offence and punishable as a murder. A mere three years later, in 1591, Pope Gregory XIV reverted the official stand back to delayed ensoulment.
It was only in 1869 that Pope Pius IX officially eliminated the catholic distinction between an animated and a non-animated foetus. Abortion at any stage was again an excommunicable offence!   
Pope Leo XIII in a couple of decrees in 1884 and 1886 made it explicitly clear that an abortion even when performed to save a mother's life was morally wrong.
Tricky casesDetermining if a particular case would meet the loophole requirements is tricky. Sister of Mercy Margaret McBride who was on the Phoenix Catholic hospital's ethics committee found this out the hard way. In 2008, she found herself excommunicated for her role in allowing an abortion to take place at the hospital. Fortunately, for rape victims, the rule is simple. 
For performing an abortion a nine year old child who had been impregnated by her raping step-father, the Archibishop Jose Cardoso Sobrinho of Recife, Brazil excommunicated her mother and the doctors who performed the procedure.  
Well, sometimes, the church has to do what God tells it to do, right?
For more Divine Loopholes, see my earlier post: Natural Family Planning and IVF.
References Vatican.va, SACRED CONGREGATION FOR THE DOCTRINE OF THE FAITH: Declaration on Procured Abortion (1974)
 Pastoral Constitution On The Church In The Modern World, Gaudium et spes, Promulgated By His Holiness, Pope Paul VI. (1965)
Therefore from the moment of its conception life must be guarded with the greatest care while abortion and infanticide are unspeakable crimes.
The good effects of our acts are then directly intended, and the regretted evil consequences are reluctantly permitted to follow because we cannot avoid them. The evil thus permitted is said to be indirectly intended. It is not imputed to us provided four conditions are verified, namely: National Catholic Reporter, "Under Vatican ruling, abortion triggers automatic excommunication", John L. Allen Jr, (2003)
- That we do not wish the evil effects, but make all reasonable efforts to avoid them;
- That the immediate effect be good in itself;
- That the evil is not made a means to obtain the good effect; for this would be to do evil that good might come of it — a procedure never allowed;
- That the good effect be as important at least as the evil effect.
 ReligiousTolerance.org, Roman Catholicism and abortion access: Overview: Evolution of Roman Catholic positions on abortion.
 Rational Wiki, Papal infallibility
 wiki.answers.com, Did the Catholic Church always unequivocally oppose abortion?
 NCROnline.org, "Nun excommunicated for allowing abortion", (2010).
 Time.com, "Nine-Year-Old's Abortion Outrages Brazil's Catholic Church", (2009).
 BBC.co.uk, "Vatican backs abortion row bishop", (2009).