notification_options.rb 813 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class SecureMailing::PGP::NotificationOptions < SecureMailing::Backend::HandlerNotificationOptions
  3. def type
  4. 'PGP'
  5. end
  6. def check_sign
  7. begin
  8. if from_key && !from_key.expired?
  9. security_options[:sign] = { success: true }
  10. end
  11. rescue ActiveRecord::RecordNotFound
  12. # no-op
  13. end
  14. end
  15. def check_encrypt
  16. begin
  17. PGPKey.for_recipient_email_addresses!(recipients)
  18. security_options[:encryption] = { success: true }
  19. rescue ActiveRecord::RecordNotFound
  20. # no-op
  21. end
  22. end
  23. private
  24. def from_key
  25. @from_key ||= begin
  26. list = Mail::AddressList.new(from.email)
  27. PGPKey.find_by_uid(list.addresses.first.to_s, only_valid: false, secret: true)
  28. end
  29. end
  30. end