Email parser software/package opitons

I’m new here but I need to write something web based that can pick up emails, parse the email fields (subject, to, body) and csv or pdf file attachments to accumulate the data and then output it in a required format that can be sent in a email POP/SMTP/IMAP.
The reason is that some automated reports are not easily digestable and can’t be customised
Additionally would be good to hold the received data and sent data in a database for further interrogation.
Any recommendations/methods on how to acheive this?
Thanks, Malcolm