in reply to Detecting bounced mails

I can't see anything wrong with how you parse the headers, offhand.

But I'd like to warn you that if you throw away all bounces, you will not know when a mail of yours gets bounced.

Speaking for myself, I wouldn't dare do that: I mistype an email address at least once a week.

Personaly, I'd parse the logs and look for valid Message-IDs. But it's not foolroof.