mail.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Sequencer::Unit::Import::Kayako::Post::Channel::Mail < Sequencer::Unit::Import::Kayako::Post::Channel::Base
  3. def mapping
  4. super.merge(
  5. to: to,
  6. cc: cc,
  7. body: original_post['body_html'] || original_post['body_text'] || '',
  8. content_type: 'text/html',
  9. )
  10. end
  11. private
  12. def article_type_name
  13. 'email'
  14. end
  15. def identify_key
  16. 'email'
  17. end
  18. def from
  19. return super if resource['is_requester'] || original_post['mailbox'].blank?
  20. original_post['mailbox']['address']
  21. end
  22. def to
  23. recipients = build_recipients('TO')
  24. # Add the mailbox address to the 'TO' field if it's a requester post.
  25. if resource['is_requester'] && original_post['mailbox'].present?
  26. recipients = "#{original_post['mailbox']['address']}#{", #{recipients}" if recipients.present?}"
  27. end
  28. recipients
  29. end
  30. def cc
  31. build_recipients('CC')
  32. end
  33. def build_recipients(field_type)
  34. return if !original_post.key?('recipients') || original_post['recipients'].empty?
  35. original_post['recipients'].filter_map do |recipient|
  36. next if recipient['type'] != field_type
  37. recipient[identify_key]
  38. end.join(', ')
  39. end
  40. end