I'm also guessing either sunroof leak or flood damage. Pull a carfax on it and see what it brings up. Unfortunately, if the car has been flood damaged, it's damn near impossible to get rid of the smell, not to mention rust and corrosion.
You have to either give the whole carpet and clotch seats (if applicable) and very good shampooing, or replace the carpet all together. I'd also scrub the floorboards under the carpet to get rid of any bacteria/mold.
Let me know if you need any help