Since you're resending from Linux, I'd really strongly suggest that you use
procmail instead of writing your own solution (assuming you just want to get this done and move on).
Procmail will allow you to do regex matches against your mail and other very sophisticated filtering/bouncing/whatnot.