Commit 86e1f41b authored by Lin Jen-Shin's avatar Lin Jen-Shin

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
parent f097e4db
...@@ -27,8 +27,7 @@ module Gitlab ...@@ -27,8 +27,7 @@ module Gitlab
mail = build_mail mail = build_mail
raise AutoGeneratedEmailError if ignore_auto_submitted!(mail)
mail.header.to_s =~ /auto-(generated|replied)/
mail_key = extract_mail_key(mail) mail_key = extract_mail_key(mail)
handler = Handler.for(mail, mail_key) handler = Handler.for(mail, mail_key)
...@@ -91,6 +90,16 @@ module Gitlab ...@@ -91,6 +90,16 @@ module Gitlab
break key if key break key if key
end end
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 end
end end
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