Created
September 1, 2010 17:53
-
-
Save rkumar/561072 to your computer and use it in GitHub Desktop.
read mails from mbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby -w | |
| # | |
| # this will only work in 1.8.7, since mailread.rb is not present after that | |
| # supply the path of any mbox file such as ~/mbox or ~/mail/read-mail | |
| # and see a listing of mails, then give a msg number and see body | |
| require 'mailread' | |
| BOLD = "\e[1m" | |
| CLEAR = "\e[0m" | |
| MAILBOX = ARGV[0] || "mbox" | |
| mbox = File.open(MAILBOX) | |
| count = lines = 0 | |
| # array of mails | |
| mails = [] | |
| # read up the warning message, we don't want it in our array | |
| msg = Mail.new(mbox) | |
| while !mbox.eof? | |
| msg = Mail.new(mbox) | |
| count += 1 | |
| m = msg.header | |
| printf("%2d : %2s [%15s] %s\n", count, m['Status'], m['From'], msg.header['Subject']) | |
| mails << msg | |
| end | |
| mbox.close | |
| #puts mails.size | |
| # ask user for a number and print body for that | |
| while true | |
| print "Enter a mail number [1 to #{mails.size}]:" | |
| n = STDIN.gets.chomp | |
| break if n.nil? || n.empty? | |
| msg = mails[n.to_i-1] | |
| body = msg.body | |
| puts | |
| string= "#{msg.header['Subject']}" | |
| puts "#{BOLD}#{string}#{CLEAR}" | |
| puts "-" * string.length | |
| puts body | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment