Functions for safely reading and writing mail files