A General Approach to Causal Mediation Analysis