Fixes: #3867 - parsing incoming mails breaks on this line "Reply-To: <>".
(cherry picked from commit e3e64f1087ff9904a0b99573ebd7e9a0e18f4629)
This commit is contained in:
parent
d71bd90ef9
commit
4ec64cf850
2 changed files with 69 additions and 1 deletions
|
@ -4,7 +4,9 @@ module Channel::Filter::ReplyToBasedSender
|
||||||
|
|
||||||
def self.run(_channel, mail, _transaction_params)
|
def self.run(_channel, mail, _transaction_params)
|
||||||
|
|
||||||
reply_to = mail[:'reply-to']
|
return if mail[:'reply-to'].blank?
|
||||||
|
|
||||||
|
reply_to = mail[:'reply-to'].gsub('<>', '').strip
|
||||||
return if reply_to.blank?
|
return if reply_to.blank?
|
||||||
|
|
||||||
setting = Setting.get('postmaster_sender_based_on_reply_to')
|
setting = Setting.get('postmaster_sender_based_on_reply_to')
|
||||||
|
|
66
spec/models/channel/filter/reply_to_based_sender_spec.rb
Normal file
66
spec/models/channel/filter/reply_to_based_sender_spec.rb
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Channel::Filter::ReplyToBasedSender, type: :channel_filter do
|
||||||
|
describe '.run' do
|
||||||
|
let(:mail_hash) { Channel::EmailParser.new.parse(<<~RAW.chomp) }
|
||||||
|
From: daffy.duck@acme.corp
|
||||||
|
To: batman@marvell.com
|
||||||
|
Subject: Anvil
|
||||||
|
Reply-To: #{reply_to}
|
||||||
|
|
||||||
|
I can haz anvil!
|
||||||
|
RAW
|
||||||
|
|
||||||
|
before do
|
||||||
|
Setting.set('postmaster_sender_based_on_reply_to', 'as_sender_of_email')
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when empty reply-to' do
|
||||||
|
let(:reply_to) { '' }
|
||||||
|
|
||||||
|
it 'keeps from' do
|
||||||
|
expect { filter(mail_hash) }
|
||||||
|
.not_to change { mail_hash[:from] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when empty reply-to realname and invalid address' do
|
||||||
|
let(:reply_to) { '<>' }
|
||||||
|
|
||||||
|
it 'keeps from' do
|
||||||
|
expect { filter(mail_hash) }
|
||||||
|
.not_to change { mail_hash[:from] }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when valid reply-to address' do
|
||||||
|
let(:reply_to) { '<bugs.bunny@acme.corp>' }
|
||||||
|
|
||||||
|
it 'sets from to reply-to address' do
|
||||||
|
expect { filter(mail_hash) }
|
||||||
|
.to change { mail_hash[:from] }.to('bugs.bunny@acme.corp')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when valid reply-to realname and address' do
|
||||||
|
let(:reply_to) { 'Bugs Bunny <bugs.bunny@acme.corp>' }
|
||||||
|
|
||||||
|
it 'sets from to reply-to realname and address' do
|
||||||
|
expect { filter(mail_hash) }
|
||||||
|
.to change { mail_hash[:from] }.to('Bugs Bunny <bugs.bunny@acme.corp>')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when valid reply-to realname and invalid address' do
|
||||||
|
let(:reply_to) { '"Bugs Bunny" <>' }
|
||||||
|
|
||||||
|
it 'sets from to reply-to realname' do
|
||||||
|
expect { filter(mail_hash) }
|
||||||
|
.to change { mail_hash[:from] }.to('"Bugs Bunny"')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue