Relying on libraries is always helpful for parsing tasks. You are right, the library will always consider the problem in more detail than the regular expression, given various cases, etc.
One Ruby library to parse Mail emails:
Mail is an online library for Ruby designed to process letters generating, parsing and sending in a simple, ruby way.
[...] Mail was designed with a very simple object-oriented system that really opens the emails that you process, if you know what you are doing, you can play with all the latest emails.
The following is an example of accessing email content:
mail = Mail.read('/path/to/message.eml') mail.envelope.from
It also allows you to analyze multiple emails, as well as check and extract attachments.
Konrad reiche
source share