Further refine+test+debug log rotation code.

Further refine+test+debug log rotation code. Insert more verbose
debugging code and correct a coding error in mail.inc.