I think I'd move the locale figuring closer to where it gets used after _send_mail is defined.