From dde97f673e67867dc467d58c31bd3c6ba7fe56a6 Mon Sep 17 00:00:00 2001 From: Christopher Vollick <0@psycoti.ca> Date: Tue, 20 May 2025 12:27:01 -0400 Subject: [PATCH] Allow Multiple DKIM Signature Headers Apparently this is a thing? Most of the emails I got don't have this, but one that I tested just happened to, so I have to handle it! We make sure there's always an array now, and then parse "each" of them, and fail if none of them are for the interac email address. I don't really care about the others, but I do worry at some point they're going to stop supporting the address I like... Either way, this works today. --- lib/interac_email.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/interac_email.rb b/lib/interac_email.rb index 47383b4b9cb122dab6b249c145929d5fa4e681fe..ade6e38a770e5b61637fb88ffa0f586d6b3400db 100644 --- a/lib/interac_email.rb +++ b/lib/interac_email.rb @@ -140,21 +140,24 @@ class InteracEmail raise Error::BadAuth, @m unless auth =~ /\sdkim=pass\s/ end - def dkim_header - @m["DKIM-Signature"] - &.value + def dkim_headers + # Apparently there can sometimes be multiple DKIM sigs + # And this library returns a scalar if there's one, or array otherwise + [@m["DKIM-Signature"]].flatten.compact.map {|h| + h.value &.split(/;\s*/) &.each_with_object({}) { |f, h| k, v = f.split("=", 2) h[k.to_sym] = v } + } end def ensure_dkim - dkim = dkim_header + dkim = dkim_headers - raise Error::DKIM, @m unless dkim - raise Error::WrongDKIM, @m unless dkim[:d] == "payments.interac.ca" + raise Error::DKIM, @m if dkim.empty? + raise Error::WrongDKIM, @m unless dkim.any? {|v| v[:d] == "payments.interac.ca" } end end