# Pull Request Template ## Description This PR adds IMAP authentication mechanism selection to Chatwoot's email inbox configuration. Users can now choose between 'plain', 'login', and 'cram-md5' authentication methods when configuring IMAP settings, providing flexibility for different email providers that require specific authentication types. https://github.com/chatwoot/chatwoot/issues/8867 The implementation includes: - Frontend dropdown with numeric keys (1, 2, 3) matching SMTP auth style - Backend API validation for allowed authentication mechanisms - Consistent 'cram-md5' format throughout the codebase - Updated IMAP service to handle different auth types properly This feature maintains consistency with existing SMTP authentication options and follows the established UI/UX patterns in the application. ## Type of change Please delete options that are not relevant. - [x] New feature (non-breaking change which adds functionality) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] Breaking change (fix or feature that would cause existing functionality not to work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? ### Manual Testing: - Tested in Docker environment - Verified IMAP auth dropdown appears in inbox settings - Confirmed all three auth mechanisms (plain, login, cram-md5) can be selected and saved - Tested API validation by attempting to save invalid auth mechanisms ### Automated Testing: - Updated existing IMAP service tests to use consistent lowercase values - Updated API controller tests for authentication parameter handling - All tests pass locally with the new changes ### Test Configuration: - Tested with both new and existing inbox configurations ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules ## Additional Notes - This feature is backward compatible and doesn't break existing IMAP configurations - The 'cram-md5' format is used consistently throughout (UI, API, storage, services) - Net::IMAP compatibility is maintained by converting to 'CRAM-MD5' internally - Follows the same pattern established by SMTP authentication configuration --------- Co-authored-by: João Santos <joao.santos@madigital.eu> Co-authored-by: Sony Mathew <sony@chatwoot.com>
82 lines
2.9 KiB
Ruby
82 lines
2.9 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: channel_email
|
|
#
|
|
# id :bigint not null, primary key
|
|
# email :string not null
|
|
# forward_to_email :string not null
|
|
# imap_address :string default("")
|
|
# imap_authentication :string default("plain")
|
|
# imap_enable_ssl :boolean default(TRUE)
|
|
# imap_enabled :boolean default(FALSE)
|
|
# imap_login :string default("")
|
|
# imap_password :string default("")
|
|
# imap_port :integer default(0)
|
|
# provider :string
|
|
# provider_config :jsonb
|
|
# smtp_address :string default("")
|
|
# smtp_authentication :string default("login")
|
|
# smtp_domain :string default("")
|
|
# smtp_enable_ssl_tls :boolean default(FALSE)
|
|
# smtp_enable_starttls_auto :boolean default(TRUE)
|
|
# smtp_enabled :boolean default(FALSE)
|
|
# smtp_login :string default("")
|
|
# smtp_openssl_verify_mode :string default("none")
|
|
# smtp_password :string default("")
|
|
# smtp_port :integer default(0)
|
|
# verified_for_sending :boolean default(FALSE), not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# account_id :integer not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_channel_email_on_email (email) UNIQUE
|
|
# index_channel_email_on_forward_to_email (forward_to_email) UNIQUE
|
|
#
|
|
|
|
class Channel::Email < ApplicationRecord
|
|
include Channelable
|
|
include Reauthorizable
|
|
|
|
AUTHORIZATION_ERROR_THRESHOLD = 10
|
|
|
|
# TODO: Remove guard once encryption keys become mandatory (target 3-4 releases out).
|
|
if Chatwoot.encryption_configured?
|
|
encrypts :imap_password
|
|
encrypts :smtp_password
|
|
end
|
|
|
|
self.table_name = 'channel_email'
|
|
EDITABLE_ATTRS = [:email, :imap_enabled, :imap_login, :imap_password, :imap_address, :imap_port, :imap_enable_ssl, :imap_authentication,
|
|
:smtp_enabled, :smtp_login, :smtp_password, :smtp_address, :smtp_port, :smtp_domain, :smtp_enable_starttls_auto,
|
|
:smtp_enable_ssl_tls, :smtp_openssl_verify_mode, :smtp_authentication, :provider, :verified_for_sending].freeze
|
|
|
|
validates :email, uniqueness: true
|
|
validates :forward_to_email, uniqueness: true
|
|
|
|
before_validation :ensure_forward_to_email, on: :create
|
|
|
|
def name
|
|
'Email'
|
|
end
|
|
|
|
def microsoft?
|
|
provider == 'microsoft'
|
|
end
|
|
|
|
def google?
|
|
provider == 'google'
|
|
end
|
|
|
|
def legacy_google?
|
|
imap_enabled && imap_address == 'imap.gmail.com'
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_forward_to_email
|
|
self.forward_to_email ||= "#{SecureRandom.hex}@#{account.inbound_email_domain}"
|
|
end
|
|
end
|