Merging in changes from qpsmtpd-dev fork

Sorry, this commit is really big.