qmd: when relaying, validate MAIL FROM against QMD

and refactored the code a little, to avoid redundancy