Scattering theory and automorphic functions