Make sure we don't close a mailbox if we didn't open one (bug #4800)