The dipole formalism for next-to-leading order QCD calculations with massive partons