Ruby MailBox file management (rmbox)

Another library for manage a mailbox as object...

reading a mailbox

The new method create a new instance, classic:

  require 'rmbox'
  mbox=Mailbox.new '/var/mail/fulano'

If the mailbox do not exit, will be created. I suggest to write some email or you'll have an empty file :D

reading emails

Each mailbox has a mail number. Lets get the mail number 3 from the mailbox.

  # return the amount of mails in the mailbox
  mbox.mails
  => 18

  # get the mail number 3 as is in the mailbox
  @myemail=mbox.get 3

If you mailbox change and you wanna reflect thats changes in you mailbox object, use the reread method:

  # read the mailbox file again
  mbox.reread

Ask a mail number bigger than existent mails will raise an exception. If your mailbox is not to big, you could use ".to_a" method for get an array with all the emails:

  # get all the emails as an array
  mbox.to_a

Then you can use, last and/or [-1] etc... but, be careful with big mailboxes and remember that you having a common array.

writing a mail to your mailbox

Write in the mailbox is append a mail to the mailbox.

  # add a email to the Mailbox
  mbox.append @myemail

  # duplicate the first email
  mbox.append(mbox.get 1)

Where @myemail is a rfc822 mail formated string. Mailbox will be "rereaded" after and before append any new mail. Remember use .append instead of write. Changes are updated (write) automatically.

deleting mails

Is very easy, just like any email client do it. Which mail number shall deleted?

  # delete mail number 2
  mbox.delete 2