Does replacing an electrical junction box require the wiring to be brought up to code?
Anything you arent modifing falls under the grandfather act. You will need to rerun or make a splice in a box in the attic (where ever it is being fed from) to extend the wire to the switch and fan to bring it up to code. You shouldnt need a permit to install a fan. If you do, it just a waste of 300 bucks