diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2017-08-03 19:29:18 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2017-08-03 19:29:18 +0800 |
commit | 86e1f41b83448423a035707a971acc7ee76a0a8d (patch) | |
tree | 7aa54e26a29aa8e32ee12b5c4e20eef4c14e443c | |
parent | f097e4dbcd26a0d122776b72ca4370890a0a3f76 (diff) | |
download | gitlab-ce-86e1f41b83448423a035707a971acc7ee76a0a8d.tar.gz |
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
-rw-r--r-- | lib/gitlab/email/receiver.rb | 13 |
1 files changed, 11 insertions, 2 deletions
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 |