notification_options.rb 949 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class SecureMailing::SMIME::NotificationOptions < SecureMailing::Backend::HandlerNotificationOptions
  3. def type
  4. 'S/MIME'
  5. end
  6. def check_sign
  7. return if from_certificate.nil?
  8. return if !from_certificate.parsed.usable?
  9. security_options[:sign] = { success: true }
  10. end
  11. def check_encrypt
  12. begin
  13. SMIMECertificate.find_for_multiple_email_addresses!(recipients, filter: { key: 'public', ignore_usable: true, usage: :encryption }, blame: true)
  14. security_options[:encryption] = { success: true }
  15. rescue ActiveRecord::RecordNotFound
  16. # no-op
  17. end
  18. end
  19. private
  20. def from_certificate
  21. @from_certificate ||= begin
  22. list = Mail::AddressList.new(from.email)
  23. SMIMECertificate.find_by_email_address(list.addresses.first.to_s, filter: { key: 'private', usage: :signature, ignore_usable: false }).first
  24. end
  25. end
  26. end