If you add and remove spell immunity, it will also immediately get rid of ongoing spells, like Entangling roots. Don't think you want that.
If you would want to block the spell, it would make things incredibly complicated. You could instead make it like Dota's Lotus Orb, where the spell will be reflected but also effective on the original unit.
Projectile spells are a bit harder to make smoothly. You may detect buff placers, or use a DDS. I think with the latter, it is possible to find the exact spell that has been cast on the basis of event damage and/or damage type.
But all of that is fairly complicated. The simplest, reasonable smooth approach would be to just have spell not be blocked and the spell be cast back by dummy immediately (or perhaps add a wait time that depends on the distance and projectile speed). And ofcourse, in the case you have triggered target abilities (such as a custom 'charge' abilty, something like that), you will have to code up the right behaviour as well.