Project

General

Profile

sendmail-32753-a.patch

Lukas Zapletal, 06/09/2021 06:57 AM

View differences:

app/models/setting/email.rb
1
require 'shellwords'
2

  
1 3
class Setting::Email < Setting
2 4
  NON_EMAIL_YAML_SETTINGS = %w(send_welcome_email email_reply_address email_subject_prefix)
5
  SENDMAIL_LOCATIONS = %w(/usr/sbin/sendmail /usr/bin/sendmail /usr/local/sbin/sendmail /usr/local/bin/sendmail)
6

  
7
  def self.sendmail_locations_hash
8
    SENDMAIL_LOCATIONS.zip(SENDMAIL_LOCATIONS).to_h
9
  end
3 10
  def self.default_settings
4 11
    domain = SETTINGS[:domain]
......
19 26
      set('smtp_password', N_("Password to use to authenticate, if required"), '', N_('SMTP password'), nil, {:encrypted => true}),
20 27
      set('smtp_authentication', N_("Specify authentication type, if required"), '', N_('SMTP authentication'), nil, { :collection => proc { {:plain => "plain", :login => "login", :cram_md5 => "cram_md5", '' => _("none")} }}),
21 28
      set('sendmail_arguments', N_("Specify additional options to sendmail"), '-i', N_('Sendmail arguments')),
22
      set('sendmail_location', N_("The location of the sendmail executable"), "/usr/sbin/sendmail", N_('Sendmail location')),
29
      set('sendmail_location', N_("The location of the sendmail executable"), "/usr/sbin/sendmail", N_('Sendmail location'), nil, { :collection => proc { sendmail_locations_hash } }),
23 30
    ]
24 31
  end
25 32
  validates :value, :length => {:maximum => 255}, :if => proc { |s| s.name == "email_subject_prefix" }
33
  def validate_sendmail_location(record)
34
    if record.value.present? && !SENDMAIL_LOCATIONS.include?(record.value)
35
      record.errors[:base] << _("Not a valid sendmail location")
36
    end
37
  end
38

  
26 39
  def self.delivery_settings
27 40
    options = {}
28 41
    all.find_each do |setting|
29 42
      extracted = {:smtp => extract_prefix(setting.name, 'smtp'), :sendmail => extract_prefix(setting.name, 'sendmail')}
30 43
      ["smtp", "sendmail"].each do |method|
31 44
        if Setting[:delivery_method].to_s == method && setting.name.start_with?(method) && setting.value.to_s.present?
32
          options[extracted[method.to_sym]] = setting.value
45
          if setting.name == "sendmail_arguments"
46
            options[extracted[method.to_sym]] = Shellwords.escape(setting.value)
47
          else
48
            options[extracted[method.to_sym]] = setting.value
49
          end
33 50
        end
34 51
      end
35 52
    end
36
-