module Mailboxer module Models module Messageable # :nodoc: 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) connect_message_to_message_attachments 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 connect_message_to_message_attachments Mailboxer::Message.class_eval do has_many :message_attachments attr_accessible :message_attachments end end def attach_files(attachments, message) return unless attachments.present? attachments.each do |m| message.message_attachments << MessageAttachment.new(file: m[:file]) end end end end end