From a69aebcd0c024cdcce86c7a2e2e2ddb026e6ba14 Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Wed, 20 May 2020 16:04:45 +0200 Subject: [PATCH] Fixes #2964 - Ensure email channel authentication to be ASCII-8Bit --- app/models/channel/driver/imap.rb | 2 +- spec/models/channel/driver/imap_spec.rb | 26 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 spec/models/channel/driver/imap_spec.rb diff --git a/app/models/channel/driver/imap.rb b/app/models/channel/driver/imap.rb index abe238500..ae4d02a1a 100644 --- a/app/models/channel/driver/imap.rb +++ b/app/models/channel/driver/imap.rb @@ -111,7 +111,7 @@ example end timeout(check_type_timeout) do - @imap.login(options[:user], options[:password]) + @imap.login(options[:user], options[:password].dup&.force_encoding('ascii-8bit')) end timeout(check_type_timeout) do diff --git a/spec/models/channel/driver/imap_spec.rb b/spec/models/channel/driver/imap_spec.rb new file mode 100644 index 000000000..8d8b20791 --- /dev/null +++ b/spec/models/channel/driver/imap_spec.rb @@ -0,0 +1,26 @@ +require 'rails_helper' + +RSpec.describe Channel::Driver::Imap do + # https://github.com/zammad/zammad/issues/2964 + context 'when connecting with a ASCII 8-Bit password' do + it 'succeeds' do + + required_envs = %w[IMAP_ASCII_8BIT_HOST IMAP_ASCII_8BIT_USER IMAP_ASCII_8BIT_PASSWORD] + required_envs.each do |key| + next if ENV[key].present? + + skip("Need ENVs #{required_envs.join(', ')}.") + end + + params = { + host: ENV['IMAP_ASCII_8BIT_HOST'], + user: ENV['IMAP_ASCII_8BIT_USER'], + password: ENV['IMAP_ASCII_8BIT_PASSWORD'], + } + + result = described_class.new.fetch(params, nil, 'check') + + expect(result.dig(:result)).to eq 'ok' + end + end +end