Class Sergi::Acts::Messageable::Mailbox
In: lib/mailbox.rb
Parent: Object

Methods

Attributes

type  [RW]  this is used to filter mail by mailbox type, use the [] method rather than setting this directly.
user  [R]  the user/owner of this mailbox, set when initialized.

Public Class methods

creates a new Mailbox instance with the given user and optional type.

Public Instance methods

alias for add

sets the mailbox type and returns itself.

params:

mailbox_type:type of mailbox to filter mail by, this can be anything, but the three most likely values for this will be the received, sent, and trash values set within the acts_as_messageable method.

returns:

self

example:

   phil = User.find(3123)

   #all mails in the user's inbox
   phil.mailbox[:inbox].mail

adds a mail message to the user‘s mailbox specified by type.

*this is used when sending a new message, all the recipients get a mail added to their inbox and the sender gets a mail in their sentbox.

params:

msg:Message object from which a new mail is created from.

returns:

new Mail.

permanantly deletes all the mail messages matched by the options. Use move_to(:trash) instead if you want to send to user‘s trash without deleting.

params:

options:see mail for acceptable options.

deletes all messages that have been trashed and match the options if passed.

params:

options:see mail for acceptable options.

return true if the user is involved in the given conversation.

returns an array of the latest Mail message for each conversation the user is involved in filtered by type, if set.

*possible use for this would be an inbox view of your mail so you can easily see the status of all the convos your involved in.

params:

options:see mail for acceptable options.

returns:

array of Mail.

example:

   phil = User.find(3123)

   #get a list of the latest received mail for each conversation
   phil.mailbox[:inbox].latest_mail

returns an array of all Mail for the user filtered by type, if set.

params:

options:all valid find options are accepted as well as an additional conversation option.
  • :conversation - Conversation object to filter mail only belonging to this conversation.
  • :conditions - same as find conditions however the array version of conditions will not work, i.e., :conditions => [‘mail.read = ?’, false] will not work here.
  • all other find options will work as expected.

returns:

array of Mail.

example:

   phil = User.find(3123)

   #get all mail messages belonging to phil
   phil.mailbox.mail

   #get all mail messages in phil's inbox associated with conversation 23
   phil.mailbox[:inbox].mail(:conversation => Conversation.find(23))

   #get all unread mail messages belonging to phil associated with conversation 23
   phil.mailbox.mail(:conversation => Conversation.find(23), :conditions => 'mail.read = false')

returns a count of mail messages filtered by type and filter, if set.

*this performs an actual sql count rather than selecting all mail and then gettin a length on the array… not a big deal but this could be something that is checked often to notify the user when they receive a new mail.

params:

filter:filters the count by the ‘read’ attribute.
  • :all - count of both read and unread mail.
  • :read - count of read mail.
  • :unread - count of unread mail.
options:see mail for acceptable options.

returns:

number of mail messages

example:

   phil = User.find(3123)

   #get number of unread mail messages in phil's inbox
   phil.mailbox[:inbox].mail_count(:unread)

marks all the mail messages matched by the options and type as read.

params:

options:see mail for acceptable options.

returns:

array of Mail.

example:

   phil = User.find(3123)

   #mark all inbox messages as read
   phil.mailbox[:inbox].mark_as_read()

marks all the mail messages matched by the options and type as unread, except for sent messages.

params:

options:see mail for acceptable options.

returns:

array of Mail.

example:

   phil = User.find(3123)

   #mark all inbox messages as unread
   phil.mailbox[:inbox].mark_as_unread()

moves all mail matched by the options to the given mailbox. sent messages stay in the sentbox.

params:

mailbox:the mailbox_type to move the mail messages to. (ex. :inbox, :trash)
options:see mail for acceptable options.

returns an array of read Mail for the user filtered by type, if set.

params:

options:see mail for acceptable options.

returns:

array of Mail.

example:

   phil = User.find(3123)

   #get all read mail in phil's inbox
   phil.mailbox[:inbox].read_mail

sets the mailbox type to the symbol corresponding to the given val.

returns an array of unread Mail for the user filtered by type, if set.

params:

options:see mail for acceptable options.

returns:

array of Mail.

example:

   phil = User.find(3123)

   #get all unread mail in phil's inbox
   phil.mailbox[:inbox].unread_mail

[Validate]