Structure and evolution of the envelopes of deeply embedded massive young stars