From 86e1f41b83448423a035707a971acc7ee76a0a8d Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 3 Aug 2017 19:29:18 +0800 Subject: Check against "Auto-Submitted: no" instead This would be much more accurate. We assume this is an auto-generated email if such header is provided, and the value is not "no". It could also be: "auto-generated", "auto-replied", or other values from extension. It seems that only "no" could mean that this is sent by a human. See: https://tools.ietf.org/html/rfc3834 --- lib/gitlab/email/receiver.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb index b3c2a8fad3e..c8f4591d060 100644 --- a/lib/gitlab/email/receiver.rb +++ b/lib/gitlab/email/receiver.rb @@ -27,8 +27,7 @@ module Gitlab mail = build_mail - raise AutoGeneratedEmailError if - mail.header.to_s =~ /auto-(generated|replied)/ + ignore_auto_submitted!(mail) mail_key = extract_mail_key(mail) handler = Handler.for(mail, mail_key) @@ -91,6 +90,16 @@ module Gitlab break key if key end end + + def ignore_auto_submitted!(mail) + # Mail::Header#[] is case-insensitive + auto_submitted = mail.header['Auto-Submitted']&.value + + # Mail::Field#value would strip leading and trailing whitespace + raise AutoGeneratedEmailError if + # See also https://tools.ietf.org/html/rfc3834 + auto_submitted && auto_submitted != 'no' + end end end end -- cgit v1.2.1