Spectra of galaxies in clusters. I - The Butcher-Oemler effect