module Mailboxer module Models module Messageable # :nodoc: included do class Mailboxer::Message has_many :message_attachments attr_accessible :message_attachments end end def send_message_mult_attach(recipients, msg_body, subject, sanitize_text = true, attachments = nil, message_timestamp = Time.now) convo = build_convo(subject, message_timestamp) message = build_message(convo, recipients, msg_body, subject, message_timestamp) attach_files(attachments, message) message.deliver false, sanitize_text end def reply(conversation, recipients, reply_body, subject=nil, sanitize_text=true, attachment=nil) subject = subject || "#{conversation.subject}" build_message(conversation, recipients, reply_body, subject, message_timestamp = Time.now) end def reply_to_sender_mult_attach(receipt, reply_body, subject = nil, sanitize_text = true, attachments = nil) message = reply(receipt.conversation, receipt.message.sender, reply_body, subject, sanitize_text) attach_files(attachments, message) message.deliver false, sanitize_text end def build_convo(subject, message_timestamp) ::Mailboxer::ConversationBuilder.new( subject: subject, created_at: message_timestamp, updated_at: message_timestamp ).build end def build_message(convo, recipients, msg_body, subject, message_timestamp) ::Mailboxer::MessageBuilder.new( sender: self, conversation: convo, recipients: recipients, body: msg_body, subject: subject, created_at: message_timestamp, updated_at: message_timestamp ).build end def attach_files(attachments, message) return if attachments.blank? attachments.each do |m| message.message_attachments << MessageAttachment.new(file: m[:file]) end end end end end