Skip to content

Commit

Permalink
Merge pull request #17132 from yrudman/do-not-group-recepients-to-sub…
Browse files Browse the repository at this point in the history
…group-when-sending-attached-report

Do not divide recipients to subgroup when sending attached report
(cherry picked from commit 22652d9)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1554533
  • Loading branch information
gtanzillo authored and simaishi committed Apr 9, 2018
1 parent ee5caad commit 7769da8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
36 changes: 9 additions & 27 deletions app/models/miq_report/notification.rb
Expand Up @@ -43,34 +43,16 @@ def notify_user_of_report(run_on, result, options)
end
end

# Avoid ActionMailer bug where the email headers get corrupted when the total length in bytes of all the recipients exceeds approx 150 bytes.
# When this happens, the addresses on the end spill over into the headers and cause the content and mime information to be ignored.
#
# Split recipient list into groups whose total length in bytes is around 100 bytes or the configured limit
cut_off = ::Settings.smtp.recipient_address_byte_limit
sub_group = []
grouped_tos = to.uniq.inject([]) do |g, t|
sub_group << t
if sub_group.join.length >= cut_off || to.index(t) == (to.length - 1)
g << sub_group
sub_group = []
end
g
end
#

begin
grouped_tos.each do |group_of_tos|
_log.info("Queuing email user: [#{user.name}] report results: [#{result.name}] to: #{group_of_tos.inspect}")
options = {
:to => group_of_tos,
:from => from,
:subject => subject,
:body => body,
:attachment => attachments,
}
GenericMailer.deliver_queue(:generic_notification, options)
end
_log.info("Queuing email user: [#{user.name}] report results: [#{result.name}] to: #{to.inspect}")
options = {
:to => to,
:from => from,
:subject => subject,
:body => body,
:attachment => attachments,
}
GenericMailer.deliver_queue(:generic_notification, options)
rescue => err
_log.error("Queuing email user: [#{user.name}] report results: [#{result.name}] failed with error: [#{err.class.name}] [#{err}]")
end
Expand Down
1 change: 0 additions & 1 deletion config/settings.yml
Expand Up @@ -1155,7 +1155,6 @@
:host: localhost
:password: ''
:port: '25'
:recipient_address_byte_limit: 100
:user_name: evmadmin
:snapshots:
:create_free_percent: 100
Expand Down

0 comments on commit 7769da8

Please sign in to comment.