Quantum theory of cavity quasimodes