A theory of the diffuse interstellar bands