20230906162437_set_mail_ssl_default.rb 836 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class SetMailSSLDefault < ActiveRecord::Migration[6.1]
  3. def up
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. update_channels %w[Google::Account Microsoft365::Account], true
  7. update_channels %w[Email::Account Email::Notification], false
  8. end
  9. def update_channels(areas, target_value)
  10. adapters = %w[pop3 imap smtp]
  11. directions = %i[inbound outbound]
  12. Channel
  13. .where(area: areas)
  14. .each do |channel|
  15. directions.each do |dir|
  16. next if adapters.exclude?(channel.options.dig(dir, :adapter))
  17. next if !channel.options[dir].key? :options
  18. channel.options[dir][:options][:ssl_verify] = target_value
  19. end
  20. channel.save!
  21. end
  22. end
  23. end