I set my app to receive incoming emails via a post from a service. The controller that receives the posts looks a little like this:
class IncomingMailsController < ApplicationController
require 'mail'
skip_before_filter :verify_authenticity_token
def create
message = Mail.new(params[:message])
message_plain = (params[:plain])
Rails.logger.info 'message2.plain:'
Rails.logger.info message2
render :text => 'success', :status => 200 # a status of 404 would reject the mail
end
end
That successfully is delivering the entire email message, replies,forward history etc. The issue is I'd like to be able to extract just the actual reply text.
Currently I get:
That's not a bad idea. Lets try that out.
On Nov 17, 2010, at 4:18 PM, XXXXX @ XXXXXXXX wrote:
> There's a new reply:
And I'd like to know how rails devs get just the reply:
That's not a bad idea. Lets try that out.
Ideas? Thanks
There's no guaranteed way to get the entire message however it's common practice to make use of a separator and then use some code to parse out the response line.
If you take a look at the code in the open source project teambox for example you see the something really similar to the following:
def strip_responses(body)
# For GMail. Matches "On 19 August 2010 13:48, User <[email protected]<proj%2Bconversation%[email protected]>> wrote:"
body.strip.
gsub(/\n[^\r\n]*\d{2,4}.*\+.*\[email protected].*:.*\z/m, '').
split("---------separator---------").first.
split("<div class='email'").first.
strip
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With