Project

General

Profile

Patch #12493 » 40-actionmailer_base_patch.rb

Jérôme BATAILLE, 2013-07-23 17:59

 
1
# Smile specific 2013-06-06
2
# Rails 2.3.14 C.f. actionmailer-2.3.14/lib/action_mailer/base.rb
3

    
4
module ActionMailer
5
  Base.class_eval do
6

    
7
    private
8

    
9
    def perform_delivery_smtp(mail)
10
      destinations = mail.destinations
11
      mail.ready_to_send
12
      sender = (mail['return-path'] && mail['return-path'].spec) || Array(mail.from).first
13

    
14
      # Smile specific : #146531 Remplir Enveloppe-From : mails en bounce
15
      # sender changed for the user making the change
16
      # only for smile members
17
      if User.current.mail.present? && User.current.mail.ends_with?('@smile.fr')
18
        sender = User.current.mail
19
#        Rails.logger.debug "==>Smile user sender=#{sender}"
20
      end
21

    
22
      smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
23
      smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
24
      smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password],
25
                 smtp_settings[:authentication]) do |smtp|
26
        smtp.sendmail(mail.encoded, sender, destinations)
27
      end
28
    end
29

    
30
    def perform_delivery_sendmail(mail)
31
      sendmail_args = sendmail_settings[:arguments]
32

    
33
      # Smile specific : #146531 Remplir Enveloppe-From : mails en bounce
34
      sender = ''
35
      sender = mail['return-path'] if mail['return-path']
36

    
37
      # sender changed for the user making the change
38
      # only for smile members
39
      if User.current.mail.present? && User.current.mail.ends_with?('@smile.fr')
40
        sender = User.current.mail
41
        Rails.logger.debug "==>Smile sendmail sender=#{sender}"
42
      end
43

    
44
      sendmail_args += " -f \"#{sender}\"" if sender.present?
45
      # END --Smile specific : #146531 Remplir Enveloppe-From : mails en bounce
46

    
47
      IO.popen("#{sendmail_settings[:location]} #{sendmail_args}","w+") do |sm|
48
        sm.print(mail.encoded.gsub(/\r/, ''))
49
        sm.flush
50
      end
51
    end
52
  end
53
end
(3-3/4)