Implement AUTH=CRAM-MD5, and refactor some code.