当 email_in_authserv_id 被设置,且传入的邮件携带一个匹配但无结果的 Authentication-Results 头(即 RFC 8601 §2.2 中定义的“无结果”形式,例如 Authentication-Results: ``mx.example.com``; none)时,创建帖子会失败并抛出以下错误:
NoMethodError: undefined method 'each' for nil
lib/email/authentication_results.rb:45:in 'block in Email::AuthenticationResults#calc_dmarc'
帖子会丢失,且发件人不会收到任何拒绝邮件。
原因: 在 parse_header 中,authres_payload 的 no_result 分支匹配成功,导致 resinfo_val 为 nil,且 parsed_resinfo 从未被赋值。最终返回的结果为 { authserv_id: "``mx.example.com``", resinfo: nil },随后 calc_dmarc 调用 result[:resinfo].each 时引发错误。
发生场景: 某些 MTA 在执行了检查但未得出结果时会添加这种“无结果”形式的头。例如,rspamd 会对其 local_addrs 中未认证的邮件(如从内部网络中继的邮件)执行此操作。该崩溃仅在创建帖子时(Email::Receiver#create_post → auth_res_action)才会显现。如果邮件在更早阶段被拒绝(例如来自陌生人的邮件),则不会触发此代码路径。
复现步骤(在 Rails 控制台中):
SiteSetting.email_in_authserv_id = "mx.example.com"
Email::AuthenticationResults.new(["mx.example.com; none"]).verdict
# => NoMethodError: undefined method 'each' for nil
建议修复方案: 在 calc_dmarc 中,将 result[:resinfo].each 改为 Array(result[:resinfo]).each do |resinfo|,或者在 parse_header 中设置 parsed_resinfo = []。这样,“无结果”头将被视为灰色(gray),这也符合其语义。
该问题在 ESR v2026.7.3 中已被发现,且 main 分支中同一行代码依然存在。