Module: HasMailbox::Models::InstanceMethods

Defined in:
lib/has_mailbox/has_mailbox.rb

Instance Method Summary collapse

Instance Method Details

#empty_mailbox(options = {}) ⇒ Object

to delete empty all of the messages

inbox message will be move as a trash message, outgoing messages / outbox will be deleted forever and trash messages also will be deleted forever from the tables.

  • :options => :inbox, :outbox, :trash

  • USAGE pass the parameter as boolean value

  • i.e : @user_obj.empty_mailbox(:trash => true)



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/has_mailbox/has_mailbox.rb', line 67

def empty_mailbox(options = {})
	if options.empty?
		self.sent_messages.delete_all
		self.received_messages.delete_all
	elsif options[:inbox]
		self.inbox.update_all(:deleted => true)
	elsif options[:outbox]
		self.outbox.delete_all
	elsif options[:trash]
		self.trash.delete_all
	end
end

#has_unread_messages?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/has_mailbox/has_mailbox.rb', line 24

def has_unread_messages?
  inbox.exists?(:opened => false)
end

#inboxObject

retrieve all receiving messages



51
52
53
# File 'lib/has_mailbox/has_mailbox.rb', line 51

def inbox
		self.received_messages.where(:deleted => false)
end

#outboxObject

retrieve all sent/outgoing messages



46
47
48
# File 'lib/has_mailbox/has_mailbox.rb', line 46

def outbox
		self.sent_messages
end

#send_message(subject, body, *recipients) ⇒ Object



38
39
40
41
42
43
# File 'lib/has_mailbox/has_mailbox.rb', line 38

def send_message(subject, body, *recipients)
	recipients.each do |rec|  
			create_message_copy(subject, body, rec)
  	create_message(subject, body, rec)	
    	end	
end

#send_message?(subject, body, *recipients) ⇒ Boolean

send message instance method

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
# File 'lib/has_mailbox/has_mailbox.rb', line 29

def send_message?(subject, body, *recipients)
	begin
send_message(subject, body, *recipients)
true	
	rescue Exception => e
		false
	end
end

#trashObject

retrieve all messages that being deleted (still in the trash but not yet destroyed)



56
57
58
# File 'lib/has_mailbox/has_mailbox.rb', line 56

def trash
	  	self.received_messages.where(:deleted => true)
end