Project

General

Profile

RE: Contacts plugin » mailer_1_.rb

redmine_messenger 0.0.9 from plugins lib/redmine_messenger/ folder - Terence Mill, 2010-11-24 17:47

 
1
class Mailer < ActionMailer::Base
2

    
3
  alias_method :create_without_messenger!, :create!
4
  
5
  def create!(method_name, *parameters)
6
    mail = create_without_messenger!(method_name, *parameters)
7

    
8
    return mail if mail.to.nil? and mail.bcc.nil?
9
    
10
    message = nil
11
    
12
    to = mail.to
13
    to ||= mail.bcc # why?
14
    
15
    to.each do |email|
16
      if user = User.find_by_mail(email) and messenger = UserMessenger.find_by_user_id(user.id) and messenger.messenger_notifications?                      
17
        if message.nil?
18
          footer = Setting[:emails_footer].gsub(/\r\n/, "\n")
19
          message = mail.body.gsub(/#{footer}.*/m, "").gsub(/[-]{3,}/, "\n").gsub(/[\n]{3,}/, "\n\n").strip
20
        end        
21
        RedmineMessenger::Messenger.send_message(messenger.messenger_id, message)
22
      end
23
    end
24

    
25
    mail
26
  end
27
    
28
end
(1-1/2)