Ruby - processing letters from text or html

From what I understand, Regex is not the best thing to use when scanning email messages as part of this document. I am wondering if there are alternatives to this? Or some better way that I don't know about?

+7
source share
1 answer

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 #=> ' mikel@test.lindsaar.net ' mail.from.addresses #=> [' mikel@test.lindsaar.net ', ' ada@test.lindsaar.net '] mail.sender.address #=> ' mikel@test.lindsaar.net ' mail.to #=> ' bob@test.lindsaar.net ' mail.cc #=> ' sam@test.lindsaar.net ' mail.subject #=> "This is the subject" mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600' mail.message_id #=> '< 4D6AA7EB.6490534@xxx.xxx >' mail.body.decoded #=> 'This is the body of the email... 

It also allows you to analyze multiple emails, as well as check and extract attachments.

+15
source

All Articles