Commit b290b81e authored by intrigeri's avatar intrigeri Committed by ng

Let Jenkins job notification email through

The automated message detection heuristic already let messages sent by cron
through. This makes sense, as there are valid use cases for sending email from
cronjobs to a Schleuder list. Similarly, there are valid use cases for sending
Jenkins job notifications to a Schleuder list. But so far we rejected these
messages: they include a Auto-Submitted header whose value is not "no".

To fix this problem, let's allow auto-submitted email when a X-Jenkins-Job
header is present.

For reference, as of current Jenkins LTS (2.176.3) running on Debian Stretch
with Java 8, messages generated by the Jenkins Mailer¹ plugin include
characteristic headers; for example:

  X-Jenkins-Job: test_Tails_ISO_stable
  X-Jenkins-Result: FAILURE
  Auto-submitted: auto-generated

[1] https://github.com/jenkinsci/mailer-plugin
parent ea92aa25
......@@ -206,11 +206,14 @@ module Mail
@recipient.match(/-bounce@/).present? ||
# Empty Return-Path
self.return_path.to_s == '<>' ||
# Auto-Submitted exists and does not equal 'no' and no cron header
# present, as cron emails have the auto-submitted header.
# Auto-Submitted exists and does not equal 'no' and:
# - no cron header is present
# - no Jenkins job notification header is present
# as these emails have the auto-submitted header.
( self['Auto-Submitted'].present? && \
self['Auto-Submitted'].to_s.downcase != 'no' && \
!self['X-Cron-Env'].present?)
!self['X-Cron-Env'].present? && \
!self['X-Jenkins-Job'].present?)
end
def keywords
......
......@@ -54,6 +54,18 @@ describe Mail::Message do
expect(mail.automated_message?).to be(false)
end
it "recognizes a Jenkins message with 'Auto-Submitted'-header NOT as automated message" do
list = create(:list)
mail = Mail.new
mail.header['Auto-submitted'] = 'auto-generated'
mail.header['X-Jenkins-Job'] = 'test_Tails_ISO_stable'
# Trigger the setting of mandatory headers.
mail.to_s
mail = Mail.create_message_to_list(mail.to_s, 'something@localhost', list).setup
expect(mail.automated_message?).to be(false)
end
context '#add_subject_prefix!' do
it 'adds a configured subject prefix' do
list = create(:list)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment