Refactor the mail-handler to address Issue 31.

@vixie here's the change requested to mail-handler.pl.

Hopefully this fits to issue 31.