(a) Any person who willfully, maliciously, and repeatedly follows or willfully and maliciously harasses another person and who makes a credible threat with the intent to place that person in reasonable fear for his or her safety, or the safety of his or her immediate family is guilty of the crime of stalking, punishable by imprisonment in a county jail for not more than one year, or by a fine of not more than one thousand dollars ($1,000), or by both that fine and imprisonment, or by imprisonment in the state prison. (b) Any person who violates subdivision (a) when there is a temporary restraining order, injunction, or any other court order in effect prohibiting the behavior described in subdivision (a) against the same party, shall be punished by imprisonment in the state prison for two, three, or four years. (c)(1) Every person who, after having been convicted of a felony under Section 273.5, 273.6, or 422, commits a violation of subdivision (a) shall be punished by imprisonment in a county jail for not more than one year, or by a fine of not more than one thousand dollars ($1,000), or by both that fine and imprisonment, or by imprisonment in the state prison for two, three, or five years. (2) Every person who, after having been convicted of a felony under subdivision (a), commits a violation of this section shall be punished by imprisonment in the state prison for two, three, or five years. (d) In addition to the penalties provided in this section, the sentencing court may order a person convicted of a felony under this section to register as a sex offender pursuant to Section 290.006. (e) For the purposes of this section, “harasses” means engages in a knowing and willful course of conduct directed at a specific person that seriously alarms, annoys, torments, or terrorizes the person, and that serves no legitimate purpose. (f) For the purposes of this section, “course of conduct” means two or more acts occurring over a period of time, however short, evidencing a continuity of purpose. Constitutionally protected activity is not included within the meaning of “course of conduct.” (g) For the purposes of this section, “credible threat” means a verbal or written threat, including that performed through the use of an electronic communication device, or a threat implied by a pattern of conduct or a combination of verbal, written, or electronically communicated statements and conduct, made with the intent to place the person that is the target of the threat in reasonable fear for his or her safety or the safety of his or her family, and made with the apparent ability to carry out the threat so as to cause the person who is the target of the threat to reasonably fear for his or her safety or the safety of his or her family. It is not necessary to prove that the defendant had the intent to actually carry out the threat. The present incarceration of a person making the threat shall not be a bar to prosecution under this section. Constitutionally protected activity is not included within the meaning of “credible threat.” (h) For purposes of this section, the term “electronic communication device” includes, but is not limited to, telephones, cellular phones, computers, video recorders, fax machines, or pagers. “Electronic communication” has the same meaning as the term defined in Subsection 12 of Section 2510 of Title 18 of the United States Code. (i) This section shall not apply to conduct that occurs during labor picketing. (j) If probation is granted, or the execution or imposition of a sentence is suspended, for any person convicted under this section, it shall be a condition of probation that the person participate in counseling, as designated by the court. However, the court, upon a showing of good cause, may find that the counseling requirement shall not be imposed. (k)(1) The sentencing court also shall consider issuing an order restraining the defendant from any contact with the victim, that may be valid for up to 10 years, as determined by the court. It is the intent of the Legislature that the length of any restraining order be based upon the seriousness of the facts before the court, the probability of future violations, and the safety of the victim and his or her immediate family. (2) This protective order may be issued by the court whether the defendant is sentenced to state prison, county jail, or if imposition of sentence is suspended and the defendant is placed on probation. (l) For purposes of this section, “immediate family” means any spouse, parent, child, any person related by consanguinity or affinity within the second degree, or any other person who regularly resides in the household, or who, within the prior six months, regularly resided in the household. (m) The court shall consider whether the defendant would benefit from treatment pursuant to Section 2684. If it is determined to be appropriate, the court shall recommend that the Department of Corrections and Rehabilitation make a certification as provided in Section 2684. Upon the certification, the defendant shall be evaluated and transferred to the appropriate hospital for treatment pursuant to Section 2684.