Capillary driven flows and wetting in porous media