fix: add email logging for source-id email-id and message-id (#7262)
* fix: mail logger for source-id email-id and message-id * added mail provided to the tracking * change the logger verb from info to error * app/jobs/inboxes/fetch_imap_emails_job.rb * codeclimate fix * remove extra filter * fixes: specs
This commit is contained in:
@@ -40,14 +40,16 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob
|
|||||||
received_mails(imap_inbox).each do |message_id|
|
received_mails(imap_inbox).each do |message_id|
|
||||||
inbound_mail = Mail.read_from_string imap_inbox.fetch(message_id, 'RFC822')[0].attr['RFC822']
|
inbound_mail = Mail.read_from_string imap_inbox.fetch(message_id, 'RFC822')[0].attr['RFC822']
|
||||||
|
|
||||||
|
mail_info_logger(channel, inbound_mail, message_id)
|
||||||
|
|
||||||
next if email_already_present?(channel, inbound_mail, last_email_time)
|
next if email_already_present?(channel, inbound_mail, last_email_time)
|
||||||
|
|
||||||
process_mail(inbound_mail, channel)
|
process_mail(inbound_mail, channel)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_already_present?(channel, inbound_mail, last_email_time)
|
def email_already_present?(channel, inbound_mail, _last_email_time)
|
||||||
processed_email?(inbound_mail, last_email_time) || channel.inbox.messages.find_by(source_id: inbound_mail.message_id).present?
|
channel.inbox.messages.find_by(source_id: inbound_mail.message_id).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
def received_mails(imap_inbox)
|
def received_mails(imap_inbox)
|
||||||
@@ -76,12 +78,21 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob
|
|||||||
received_mails(imap_inbox).each do |message_id|
|
received_mails(imap_inbox).each do |message_id|
|
||||||
inbound_mail = Mail.read_from_string imap_inbox.fetch(message_id, 'RFC822')[0].attr['RFC822']
|
inbound_mail = Mail.read_from_string imap_inbox.fetch(message_id, 'RFC822')[0].attr['RFC822']
|
||||||
|
|
||||||
|
mail_info_logger(channel, inbound_mail, message_id)
|
||||||
|
|
||||||
next if channel.inbox.messages.find_by(source_id: inbound_mail.message_id).present?
|
next if channel.inbox.messages.find_by(source_id: inbound_mail.message_id).present?
|
||||||
|
|
||||||
process_mail(inbound_mail, channel)
|
process_mail(inbound_mail, channel)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mail_info_logger(channel, inbound_mail, message_id)
|
||||||
|
return if Rails.env.test?
|
||||||
|
|
||||||
|
Rails.logger.info("
|
||||||
|
#{channel.provider} Email id: #{inbound_mail.from} and message_source_id: #{inbound_mail.message_id}, message_id: #{message_id}")
|
||||||
|
end
|
||||||
|
|
||||||
def authenticated_imap_inbox(channel, access_token, auth_method)
|
def authenticated_imap_inbox(channel, access_token, auth_method)
|
||||||
imap = Net::IMAP.new(channel.imap_address, channel.imap_port, true)
|
imap = Net::IMAP.new(channel.imap_address, channel.imap_port, true)
|
||||||
imap.authenticate(auth_method, channel.imap_login, access_token)
|
imap.authenticate(auth_method, channel.imap_login, access_token)
|
||||||
@@ -113,6 +124,8 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob
|
|||||||
Imap::ImapMailbox.new.process(inbound_mail, channel)
|
Imap::ImapMailbox.new.process(inbound_mail, channel)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
|
ChatwootExceptionTracker.new(e, account: channel.account).capture_exception
|
||||||
|
Rails.logger.error("
|
||||||
|
#{channel.provider} Email dropped: #{inbound_mail.from} and message_source_id: #{inbound_mail.message_id}, message_id: #{message_id}")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Making sure the access token is valid for microsoft provider
|
# Making sure the access token is valid for microsoft provider
|
||||||
|
|||||||
Reference in New Issue
Block a user