Class: QuotesMailbox

Inherits:
ApplicationMailbox show all
Defined in:
app/mailboxes/quotes_mailbox.rb

Constant Summary collapse

RECIPIENT_FORMAT =
/quo(?:_case)?\+id(.+)@/i

Constants inherited from ApplicationMailbox

ApplicationMailbox::DIRECT_FILE_EXTENSIONS, ApplicationMailbox::FETCHABLE_MIME_TYPES, ApplicationMailbox::FETCH_MAX_SIZE, ApplicationMailbox::GDRIVE_FILE_RE, ApplicationMailbox::GDRIVE_OPEN_RE, ApplicationMailbox::MAX_FILENAME_LENGTH

Instance Method Summary collapse

Methods inherited from ApplicationMailbox

#attempt_url_download, #collect_fetchable_urls, #create_activity, #create_communication, #fetch_linked_files, #find_sender_party, #get_resource_id, #inline_or_attachment_part?, #process_attachments, #process_content, #replace_cid_references, #sanitize_attachment_filename

Instance Method Details

#get_quoteObject



39
40
41
42
# File 'app/mailboxes/quotes_mailbox.rb', line 39

def get_quote
  @quote = Quote.find(get_resource_id) rescue nil
  Rails.logger.info "Quote Mailbox, quote retrieved. ID: #{@quote&.id}"
end

#processObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/mailboxes/quotes_mailbox.rb', line 4

def process
  get_quote

  return unless @quote.present?

  Rails.logger.info "Processing Quote Mail for quote ID #{@quote.id}"
  if mail.from.any?{|a| a.include?('@warmlyyours.com')}
    comm_state = 'sent'
    comm_direction = 'outbound'
    act_type = 'EMAILOUT'
    complete_act = true
  else
    comm_state = 'received'
    comm_direction = 'inbound'
    act_type = 'EMAILIN'
    complete_act = false
  end

  note = process_content(mail)

  comm = create_communication(@quote, mail, note, comm_state, comm_direction)

  process_attachments(comm, mail)

  follow_up_activity_type = ActivityType.find_by(task_type: act_type)
  sender_party = find_sender_party(mail)
  if sender_party.present? && sender_party.is_employee?
    assigned_resource = sender_party
  else
    assigned_resource = follow_up_activity_type.determine_assigned_resource(@quote.customer) || @quote.customer.sales_manager
  end
  create_activity(@quote, act_type, assigned_resource, comm, complete_act)

end