On Nov 17, 2010, at 5:40 PM, CuriousNewbie wrote: > Hello, 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
In real life it will be a bit more complicated since that delineator isn't always the same. Sometimes it's what you have there "on such and such, so and so worte" and sometimes it's "--- Original Message" and sometimes it's something else. So you'll need to check for all the common ones and probably want the ability to see the entire message in case it messes up or in cases like this message where I've replied *below* that delineator. But, for your case above assuming the plain text message is in a variable str then... str.sub(/\A.*^\SOn \w+ \d+, \d+ at.* wrote:.*/m, '') or something close to that ought to do it. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

