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

  • SEARCH
  • Home
  • 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 7535211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:15:17+00:00 2026-05-30T06:15:17+00:00

I’m a super-novice with Ruby, and playing around with the IMAP library. The below

  • 0

I’m a super-novice with Ruby, and playing around with the IMAP library. The below program seems to work but it goes on forever until all messages are loaded. How would I limit the output to an X number of messages, like if I only wanted to show 10? I imagine it’s some sort of “if envelope =” — but don’t know what to put there. Thanks!

require 'net/imap'
imap = Net::IMAP.new('mail.domain.com')
imap.authenticate('LOGIN', ' ', ' ')
imap.examine('INBOX')
imap.search(["SEEN"]).each do |message_id|
  envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
  puts "#{envelope.from[0].name}: \t#{envelope.subject}"
end

Not sure if appropriate here or if I should make a new question, but using the “SINCE” idea from below, how would I display a count of all the emails (elements in the array) fetched?

imap.examine('INBOX')
  imap.search(["SINCE", "17-Feb-2012"]).each do |message_id| 
  envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
  puts "#{envelope.from[0].name}: \t#{envelope.subject}"
   puts "#{envelope.count}"
  end

The above puts the number 10 after every line, regardless of the amount of emails returned. How would I a) only put the result at the end of all the emails listed and b) find a true count of the elements in the array?

OK, figured out the second part:

require 'net/imap'
imap = Net::IMAP.new('mail.domain.com')
imap.authenticate('LOGIN', 'username', 'password')
imap.examine('INBOX')
mail_count = imap.search(["SINCE", "20-Feb-2012"]) 
puts mail_count.count
  • 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-05-30T06:15:18+00:00Added an answer on May 30, 2026 at 6:15 am

    You can use slice to get only N results:

    imap.search(["SEEN"]).slice(0, 10).each do |message_id|
      ...
    end
    

    The first parameter (here is 0) specified the start position, and the second the total number you need.

    Note: based on IMAP’s search method’s implementation, the underlying calling might still fetch all messages from the server.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.