In Mahan's book, equation (4.127), he claims that \begin{align} &\frac{1}{\beta}\sum_{ik_n} \frac{1}{ik_n-\xi_1}\frac{1}{ik_n-\xi_2}\frac{1}{ik_n-\xi_3} \\ =& \frac{n_F(\xi_1)}{(\xi_1-\xi_2)(\xi_1-\xi_3)} + \frac{n_F(\xi_2)}{(\xi_2-\xi_1)(\xi_2-\xi_3)} + \frac{n_F(\xi_3)}{(\xi_3-\xi_1)(\xi_3-\xi_2)} - \pi^2 n_F(\xi_1)\delta(\xi_1-\xi_2)\delta(\xi_1-\xi_3) \end{align} where $ik_n$ are fermionic (half-integer) frequencies and $n_F$ is the Fermi distribution function. Because one eventually integrates over $\xi_1,\xi_2,\xi_3$, one needs to be careful about the choice of contour when computing the sum via residues; namely, one should avoid crossing the real axis.
The contour one should take is two infinite-radius semicircles, one $i\epsilon$ above and one $i\epsilon$ below the real axis, both with counter-clockwise orientation. Hence, the Matsubara sum evaluates to the difference between the integrals $\int_{-\infty+i\epsilon}^{\infty+i\epsilon} - \int_{-\infty-i\epsilon}^{\infty-i\epsilon}$.
The first three terms of (4.127) are simple to obtain, and indeed what you would expect if one just fixes $\xi_1,\xi_2,$ and $\xi_3$ to be some constant value. However, I am having trouble demonstrating that the last term is actually correct.
Naively, one would want to use the Sokhotski–Plemelj theorem $$\frac{1}{x+i\epsilon} = P\frac{1}{x} - i\pi\delta(x)$$ term-by-term, but such a relation only holds when the function against which you are integrating is analytic. The delta-functions in the 4th term of (4.127) clearly put all the poles at the same spot, disallowing this naive replacement term-by-term.
How should one go about demonstrating that this 4th term is really the correct $\epsilon\rightarrow 0$ limit? Or is Mahan even correct?
Edit: Also, this formula implies that interchanging the Matsubara sum and the momentum integrals changes the answer; but I would've expected this not to be the case. It is curious to me that you are free to interchange with two factors, but not with three or more. Why is this the case, and which one should I consider to be "correct" order of operations and why?