In most cases, the problem is caused by a build-up of dirt and debris around the sunroof seal. When it rains, the water has nowhere to go but into your car. If you're dealing with a leaking sunroof, your best bet is to take it to a professional and have them take a look. In the meantime, you can try cleaning foggy rear view mirror; that always makes me feel better when it's raining.