Return to Snippet

Revision: 31302
at September 2, 2010 14:16 by rkumar


Initial Code
#!/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

Initial URL

                                

Initial Description

                                

Initial Title
Read mbox contents

Initial Tags
ruby

Initial Language
Ruby