(a) A former municipal employee who knowingly acts as agent or attorney for or receives compensation, directly or indirectly from anyone other than the same city or town in connection with any particular matter in which the city or town is a party or has a direct and substantial interest and in which he participated as a municipal employee while so employed, or (b) a former municipal employee who, within one year after his last employment has ceased, appears personally before any agency of the city or town as agent or attorney for anyone other than the city or town in connection with any particular matter in which the same city or town is a party or has a direct and substantial interest and which was under his official responsibility as a municipal employee at any time within a period of two years prior to the termination of his employment, or (c) a partner of a former municipal employee who knowingly engages, during a period of one year following the termination of the latter's employment by the city or town, in any activity in which the former municipal employee is himself prohibited from engaging by clause (a), or (d) a partner of a municipal employee who knowingly acts as agent or attorney for anyone other than the city or town in connection with any particular matter in which the same city or town is a party or has a direct and substantial interest and in which the municipal employee participates or has participated as a municipal employee or which is the subject of his official responsibility, shall be punished by a fine of not more than $10,000, or by imprisonment in the state prison for not more than 5 years, or in a jail or house of correction for not more than 2 1/2 years, or both. If a partner of a former municipal employee or of a special municipal employee is also a member of another partnership in which the former or special employee has no interest, the activities of the latter partnership in which the former or special employee takes no part shall not thereby be subject to clause (c) or (d).
Notwithstanding the provisions of clause (b), a former town counsel who acted in such capacity on a salary or retainer of less than two thousand dollars per year shall be prohibited from appearing personally before any agency of the city or town as agent or attorney for anyone other than the city or town only in connection with any particular matter in which the same city or town is a party or has a direct and substantial interest and in which he participated while so employed.
This section shall not prevent a present or former special municipal employee from aiding or assisting another person for compensation in the performance of work under a contract with or for the benefit of the city or town; provided, that the head of the special municipal employee's department or agency has certified in writing that the interest of the city or town requires such aid or assistance and the certification has been filed with the clerk of the city or town. The certification shall be open to public inspection.