Skip to content

Instantly share code, notes, and snippets.

@boy-jer
Forked from ahawkins/email.rb
Created May 24, 2012 14:12
Show Gist options
  • Save boy-jer/2781796 to your computer and use it in GitHub Desktop.
Save boy-jer/2781796 to your computer and use it in GitHub Desktop.
class Email
class Email < Message
attr_accessor :to, :cc, :bcc
validates :to, :presence => true, :on => :create
validates :to, :cc, :bcc, :emails => true
normalize_attribute :subject, :message
attr_accessible :to, :cc, :bcc, :subject, :message
def set_participants
self << sender
[to, cc, bcc].flatten.compact.each do |address|
if matched_user = account.users.with_email(address).first
self << matched_user
end
end
[to, cc, bcc].flatten.compact.each do |address|
self << account.find_user_or_contact_by_email_or_create_contact(address) do |contact|
contact.user = users.first
end
end
end
def store_delivery_info
self.delivery_info = {
:to => [to].flatten.compact,
:cc => [cc].flatten.compact,
:bcc => [bcc].flatten.compact
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment