ruby on rails - While processing an email reply how can I ignore any email client specifics & the history? -


I have a rail application that processes incoming email via IMAP. Currently a method is used to find parts of a TMail object for the type of content:

  def self.search_parts_for_content_type (parts, content_type = 'text / html') Parts If part.content_type == content_type is back part. Else if part.multipart? If body = self.search_parts_for_content_type (part.parts, content_type) returns body end and end and end returns and  

These emails are typically in response to an html email Is sent to the place. (The original outbound email is never the same.) In the body text, the above method has an entire history of email and I just want to parse the answer text.

  1. I am wondering if something "please answer above this line ---" 'text at the top of the mail' "as I have seen in the 37 Signal App .

  2. Is there another way to ignore specific additional emails for the client, besides other regular expressions (which I have not yet) and every mail client? They all think about their own credentials at the top of any answer.

I just have to parse the email reply to a project I am doing I have finished using pattern matching to identify part of the response, so users will not be worried about where to include their answer.

The good news is that implementation is not really very difficult. The hard part is just testing all the different email clients and services that you want to support and find out how to identify each one. Usually, you can either send message ID or X-Mailer or Return -Path header can be used to determine where the incoming email comes from.

Here is a method that takes a Tellee object and removes part of the response message and returns that it was sent with the email client / service, assuming you have the original message: Name And the address constant contains FROM_NAME and FROM_ADDRESS .

  def find_reply (email) message_id = email Message_ID ('') x_mailer = email.header_string ('x-mailer') # For optimization, this list can be ordered from the most popular to the least popular email client / service rules: [['Gmail', Lambda {Message_id = ~ /.+gmail\.com>\z/}, /^.*#{FROM_NAME}\s+<#{FROM_ADDRESS}>\s*wrote:.*$/], ['Yahoo ! Mail ', lambda {message_id = ~ /.+yahoo\.com>\z/}, / ^ _ + \ nFrom: # {FROM_NAME} & lt; # {FROM_ADDRESS} & gt; $ /], ['Microsoft live mail / hotmail', lambda {email.header_string ('return-path') = ~ / & lt;; + @ (Hotmail | live) .com> /}, /^Date:.+\nSubject:.+\nFrom: # {FROM_ADDRESS} $ /], ['Outlook Express'], Lambda {x_mailer = ~ / Microsoft Outlook Express /} ----- Original message ----- $ /], ['Outlook', lambda {x_mailer = ~ / Microsoft Office Outlook /}, / ^ \ s * _ + \ s * \ n From: # {FROM_NAME} * $ /], # TODO: other email clients / services # generic fallback [nil, lambda {true}, /^.*#{FROM_ADDRESS}.*$/]] # to use the whole body as a reply Default (Maybe the user has removed the original message when they answered?) Notes = email.body source = zero # Try to find out which email service / customer sent the rules of this message. Search | R | If R [1] Try removing call # answer. If we search for it, save it and cancel the search Answer_match = email.body.match (r [2]) If answer_match notes = email.body [0, answer_match.begin (0)] source = r [0] Next True End End End Notes Column, source] end  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -