How to create or update a contact and relate to a case

Hi,

I setup an inbound email to capture emails as cases. I want to relate created case to an existing contact. If there is no contact associated with the sender email, I want to create new contact. Please let me know what should I do.
Thank you