Moved handle function to Mail module.
Made a code fragment more readable, by extracting a helper function.