trabajo-afectivo/lib/sequencer/unit/import/kayako/post/channel/mail.rb

66 lines
1.8 KiB
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class Sequencer
class Unit
module Import
module Kayako
module Post
module Channel
class Mail < Sequencer::Unit::Import::Kayako::Post::Channel::Base
def mapping
super.merge(
to: to,
cc: cc,
body: original_post['body_html'] || original_post['body_text'] || '',
content_type: 'text/html',
)
end
private
def article_type_name
'email'
end
def identify_key
'email'
end
def from
return super if resource['is_requester'] || original_post['mailbox'].blank?
original_post['mailbox']['address']
end
def to
recipients = build_recipients('TO')
# Add the mailbox address to the 'TO' field if it's a requester post.
if resource['is_requester'] && original_post['mailbox'].present?
recipients = "#{original_post['mailbox']['address']}#{", #{recipients}" if recipients.present?}"
end
recipients
end
def cc
build_recipients('CC')
end
def build_recipients(field_type)
return if !original_post.key?('recipients') || original_post['recipients'].empty?
original_post['recipients'].filter_map do |recipient|
next if recipient['type'] != field_type
recipient[identify_key]
end.join(', ')
end
end
end
end
end
end
end
end