Cancel pending mail operations when going offline or on quit

This used to be done in mail_cancel_all(), but since commit 8ae3cc32830179e09
the function is gone and the mail operations are not cancelled, which
prevents the application to go offline or to quit in a timely manner,
because it's waiting for a finish of possibly expensive operations.