Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
method to extract parts from a rails Mail::Message
def parts(email)
splits = email.encoded.split(/(\r\n)*----==_mimepart_[a-zA-Z0-9_]+(\r\n)*/)
parts = {header: splits[0]}
splits[1..-2].each do |part|
headers, body = part.split(/\r\n\r\n/, 2)
if(m = /Content-Type: ([^; ]+);?\s/.match(headers))
type = m[1]
parts[type] = OpenStruct.new(headers:headers, body:body)
end
end
return parts
end
#example of using this within rspec
it "should have content" do
email = ActionMailer::Base.deliveries.last
email.should_not be_nil
parts = parts(email)
parts.keys.should include('text/html')
parts.keys.should include('text/plain')
parts["text/plain"].body.should match(something)
parts["text/html"].body.should match(something_else)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.