Moved mail processing to function process_mail(file_name), reformatted.