Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7945087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:45:03+00:00 2026-06-04T00:45:03+00:00

I’m using the Mailman gem to process incoming email for my Rails app. My

  • 0

I’m using the Mailman gem to process incoming email for my Rails app. My application looks for a YAML document in the plain-text email and then loads it into a Ruby object for further manipulation by the app.

However, I want to be able to plan ahead for email clients that might respond with a multi-part email. I need to get the plain-text part of the email and pass it into the YAML parser.

For some reason, it’s still having problems parsing the YAML. I’m guessing because it’s not really getting the plain text part here.

Is there a better way to get the text/plain part of an email with Mailman? Should I scrap Mailman and just get down and dirty with ActionMailer instead?

Mailman::Application.run do
    default do
        begin
            message.parts.each do |part|
                Mailman.logger.info part.content_type
                if part.content_type == 'text/plain; charset=ISO-8859-1' # My poor way of getting the text part
                    the_yaml = part.body.decoded.scan(/(\-\-\-.*\.\.\.)/m).first.last # Find the YAML doc in the email and assign it to the_yaml
                    ruby_obj = YAML::load(the_yaml.sub(">", "")) # Remove any >'s automatically added by email clients

                    if ruby_obj['Jackpots']
                        ruby_obj['Jackpots'].each do |jackpot|
                            jp = Jackpot.find(jackpot['jackpot']['id'])
                            jp.prize = jackpot['jackpot']['prize']
                            jp.save
                        end
                    end
                end
            end
        rescue Exception => e
                Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
                Mailman.logger.error [e, *e.backtrace].join("\n")
        end
    end
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:45:05+00:00Added an answer on June 4, 2026 at 12:45 am

    I was able to find a little bit better way to handle getting the text part of the email.

    Mailman::Application.run do
        default do
            begin           
                if message.multipart?
                    the_message = message.text_part.body.decoded
                else
                    the_message = message.body.decoded
                end
    
                the_yaml = the_message.sub(">", "").scan(/(\-\-\-.*\.\.\.)/m).first.last
                ruby_obj = YAML::load(the_yaml)
    
                if ruby_obj['Jackpots']
                    ruby_obj['Jackpots'].each do |jackpot|
                        jp = Jackpot.find(jackpot['jackpot']['id'])
                        jp.prize = jackpot['jackpot']['prize']
                        jp.save
                    end
                end
    
            rescue Exception => e
                    Mailman.logger.error "Exception occurred while receiving message:\n#{message}"
                    Mailman.logger.error [e, *e.backtrace].join("\n")
            end
        end
    end
    

    And then after running it through the debugger and inspecting after the text part was successfully parsed. It would get hung up on the YAML loading. Turns out, a couple of my lines were too long, to the email client inserted a newline, breaking a comment in my YAML, and thus breaking the whole YAML document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.