I think the spray foam is a bad idea. Even though I brought it up, I also think the packing peanut idea is a bad one as well. The reason being that what if you need to run a new halyard or anchor light wire inside the mast without sewing the ends of the halyard together or taping the wires together to pull them through the mast? If the halyard parts inside the mast, You will have to climb the mast and try to push a rope through the peanuts or through that foam... same with the wire. It's not going to happen. As I said, my neighbor has the peanuts in his mast and is trying to figure out how to add a spinnaker halyard. The only way I can see doing it is to run it externally with a cheek block at the top of the mast, or pull the mast and have the peanuts drop out.
I only offered it up as a temporary suggestion until you can pull the mast and do it correctly. At least with the peanuts, you can blow them out with an air compressor. The spray foam is going to be permanent until it degrades which could be a long time.