automagic undivert and friends

Fixes #1306 and #867.

Geoff, please double-check 06eac80 -- I'm pretty sure that was an error.