fix: Terminate IMAP connection after the job is complete (#9225)
This commit is contained in:
@@ -3,10 +3,17 @@ require 'net/imap'
|
||||
class Imap::BaseFetchEmailService
|
||||
pattr_initialize [:channel!]
|
||||
|
||||
def perform
|
||||
def fetch_emails
|
||||
# Override this method
|
||||
end
|
||||
|
||||
def perform
|
||||
inbound_emails = fetch_emails
|
||||
terminate_imap_connection
|
||||
|
||||
inbound_emails
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authentication_type
|
||||
@@ -105,6 +112,13 @@ class Imap::BaseFetchEmailService
|
||||
imap
|
||||
end
|
||||
|
||||
def terminate_imap_connection
|
||||
imap_client.logout
|
||||
rescue Net::IMAP::Error => e
|
||||
Rails.logger.info "Logout failed for #{channel.email} - #{e.message}."
|
||||
imap_client.disconnect
|
||||
end
|
||||
|
||||
def build_mail_from_string(raw_email_content)
|
||||
Mail.read_from_string(raw_email_content)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Imap::FetchEmailService < Imap::BaseFetchEmailService
|
||||
def perform
|
||||
def fetch_emails
|
||||
fetch_mail_for_channel
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Imap::MicrosoftFetchEmailService < Imap::BaseFetchEmailService
|
||||
def perform
|
||||
def fetch_emails
|
||||
return if channel.provider_config['access_token'].blank?
|
||||
|
||||
fetch_mail_for_channel
|
||||
|
||||
Reference in New Issue
Block a user