For the contour you describe in your text, you have to indent about the poles at $z=0$ and $z=1$. In that case, the contour integral
$$\oint_C dz \frac{e^{i a z}}{e^{2 \pi z}-1}$$
is split into $6$ segments:
$$\int_{\epsilon}^R dx \frac{e^{i a x}}{e^{2 \pi x}-1} + i \int_{\epsilon}^{1-\epsilon} dy \frac{e^{i a R} e^{-a y}}{e^{2 \pi R} e^{i 2 \pi y}-1} + \int_R^{\epsilon} dx \frac{e^{-a} e^{i a x}}{e^{2 \pi x}-1} \\+ i \int_{1-\epsilon}^{\epsilon} dy \frac{ e^{-a y}}{e^{i 2 \pi y}-1} + i \epsilon \int_{\pi/2}^0 d\phi \:e^{i \phi} \frac{e^{i a \epsilon e^{i \phi}}}{e^{2 \pi \epsilon e^{i \phi}}-1}+ i \epsilon \int_{2\pi}^{3 \pi/2} d\phi\: e^{-a} e^{i \phi} \frac{e^{i a \epsilon e^{i \phi}}}{e^{2 \pi \epsilon e^{i \phi}}-1}$$
The first integral is on the real axis, away from the indent at the origin. The second integral is along the right vertical segment. The third is on the horizontal upper segment. The fourth is on the left vertical segment. The fifth is around the lower indent (about the origin), and the sixth is around the upper indent, about $z=i$.
We will be interested in the limits as $R \rightarrow \infty$ and $\epsilon \rightarrow 0$. The first and third integrals combine to form, in this limit,
$$(1-e^{-a}) \int_0^{\infty} dx \frac{e^{i a x}}{e^{2 \pi x}-1}$$
The fifth and sixth integrals combine to form, as $\epsilon \rightarrow 0$:
$$\frac{i \epsilon}{2 \pi \epsilon} \left ( -\frac{\pi}{2}\right) + e^{-a} \frac{i \epsilon}{2 \pi \epsilon} \left ( -\frac{\pi}{2}\right) = -\frac{i}{4} (1+e^{-a}) $$
The second integral vanishes as $R \rightarrow \infty$. The fourth integral, however, does not, and must be evaluated, at least partially. We rewrite it, as $\epsilon \rightarrow 0$:
$$-\frac{1}{2} \int_0^1 dy \frac{e^{-a y} e^{- i \pi y}}{\sin{\pi y}} = -\frac{1}{2} PV\int_0^1 dy \: e^{-a y} \cot{\pi y} + \frac{i}{2} \frac{1-e^{-a}}{a}$$
where
$$PV\int_0^1 dy \: e^{-a y} \cot{\pi y} = \lim_{\epsilon \to 0} \int_{\epsilon}^{1-\epsilon} dy \: e^{-a y} \cot{\pi y}$$
is the Cauchy principal value of that integral. By Cauchy's theorem, the contour integral is zero because there are no poles within the contour. Thus,
$$(1-e^{-a}) \int_0^{\infty} dx \frac{e^{i a x}}{e^{2 \pi x}-1} -\frac{i}{4} (1+e^{-a}) -\frac{1}{2} PV \int_0^1 dy \: e^{-a y} \cot{\pi y} + \frac{i}{2} \frac{1-e^{-a}}{a}=0$$
Now take the imaginary part of the above equation - note that the nasty Cauchy PV integral drops out - and get
$$(1-e^{-a}) \int_0^{\infty} dx \frac{\sin{ a x}}{e^{2 \pi x}-1} = \frac{1}{4} (1+e^{-a})-\frac{1}{2} \frac{1-e^{-a}}{a}$$
or, after a little algebra and simplifying things, we get:
$$\int_0^{\infty} dx \frac{\sin{ a x}}{e^{2 \pi x}-1} = \frac14 \coth{\left (\frac{a}{2}\right )} - \frac{1}{2 a}$$
Use parity to extend the domain of integration from $-\infty$ to $\infty$. Shift the contour of integration down by $\frac{i\pi}{2}$ to avoid pole $x=0$. Then compute separately four integrals (actually, it suffices to compute one of them and then to change parameters accordingly)
$$\int_{-\infty-\frac{i\pi}{2}}^{\infty-\frac{i\pi}{2}}\frac{e^{(\pm a\pm ib)x}dx}{\sinh x}$$
using the rectangle $$-R-\frac{i\pi}{2}\rightarrow R-\frac{i\pi}{2}\rightarrow R+\frac{i\pi}{2} \rightarrow -R+\frac{i\pi}{2} \rightarrow -R-\frac{i\pi}{2}$$ with $R\rightarrow\infty$.
For example, let us compute
\begin{align}
\int_{\text{rectangle}}\frac{e^{(a+ib)z}dz}{\sinh z}\substack{R\rightarrow\infty\\=}\int_{-\infty-\frac{i\pi}{2}}^{\infty-\frac{i\pi}{2}}\frac{e^{(a+ib)z}dz}{\sinh z}-
\int_{-\infty+\frac{i\pi}{2}}^{\infty+\frac{i\pi}{2}}\frac{e^{(a+ib)z}dz}{\sinh z}=\\
=\left(1+e^{\pi i (a+ib)}\right)\int_{-\infty-\frac{i\pi}{2}}^{\infty-\frac{i\pi}{2}}\frac{e^{(a+ib)z}dz}{\sinh z}
\end{align}
On the other hand, the integral over rectangle is equal to $2\pi i$ (the only pole inside is $z=0$ and the residue is $1$). Therefore,
$$\int_{-\infty-\frac{i\pi}{2}}^{\infty-\frac{i\pi}{2}}\frac{e^{(a+ib)z}dz}{\sinh z}=\frac{2\pi i}{1+e^{\pi i (a+ib)}},$$
and the initial integral evaluates to
$$\frac{2\pi i}{8}\left(\frac{1}{1+e^{\pi i (a+ib)}}-\frac{1}{1+e^{\pi i (-a+ib)}}+\frac{1}{1+e^{\pi i (a-ib)}}-\frac{1}{1+e^{\pi i (-a-ib)}}\right)=\frac{\pi\sin\pi a}{2\left(\cos\pi a+\cosh\pi b\right)}.$$
Best Answer
I have a simple way to calculate your old question. Note $$ \frac{\sinh(ax)}{\sinh(\pi x)} \cos(bx) = \frac{\sinh(ax)}{\sinh(\pi x)}\cosh(ibx)=\frac{\sinh((a+bi)x)+\sinh((a-bi)x)}{\sinh(\pi x)} $$ and $$ \int_0^\infty\frac{\sinh(ax)}{\sinh(bx)}dx=\frac{\pi}{2b}\tan\frac{a\pi}{2b}. $$ So \begin{eqnarray} I&=&\int_0^\infty\frac{\sinh(ax)}{\sinh(\pi x)} \cos(bx)dx\\ &=&\int_0^\infty\frac{\sinh((a+bi)x)+\sin((a-bi)x)}{\sinh(\pi x)}dx\\ &=&\frac{1}{2}\tan\frac{a+bi}{2}+\frac{1}{2}\tan\frac{a-bi}{2}\\ &=&\frac{\sin a}{\cos a + \cosh b}. \end{eqnarray}