From 189dfa509b4750f1e4cc6f43f6565edd3a35139c Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Wed, 28 Jul 2021 17:01:42 +0000 Subject: [PATCH] fix(dkim): fixes bug with signing dkim bodies --- lib/postal/dkim_header.rb | 9 +- .../dkim_signing/{email.msg => email1.msg} | 0 spec/examples/dkim_signing/email2.msg | 1016 +++++++++++++++++ spec/lib/postal/dkim_header_spec.rb | 2 +- 4 files changed, 1022 insertions(+), 5 deletions(-) rename spec/examples/dkim_signing/{email.msg => email1.msg} (100%) create mode 100644 spec/examples/dkim_signing/email2.msg diff --git a/lib/postal/dkim_header.rb b/lib/postal/dkim_header.rb index 998e9a7..50796b6 100644 --- a/lib/postal/dkim_header.rb +++ b/lib/postal/dkim_header.rb @@ -13,7 +13,7 @@ module Postal end @domain = domain @message = message - @raw_headers, @raw_body = @message.split(/\r?\n\r?\n/, 2) + @raw_headers, @raw_body = @message.gsub(/\r?\n/, "\r\n").split(/\r\n\r\n/, 2) end def dkim_header @@ -76,17 +76,18 @@ module Postal # a. Reduce whitespace # + # * Reduce all sequences of WSP within a line to a single SP character. + content.gsub!(/[ \t]+/, ' ') + # * Ignore all whitespace at the end of lines. Implementations MUST NOT # remove the CRLF at the end of the line. content.gsub!(/ \r\n/, "\r\n") - # * Reduce all sequences of WSP within a line to a single SP character. - content.gsub!(/[ \t]+/, ' ') - # b. Ignore all empty lines at the end of the message body. content.gsub!(/[ \r\n]*\z/, '') content += "\r\n" + content end end diff --git a/spec/examples/dkim_signing/email.msg b/spec/examples/dkim_signing/email1.msg similarity index 100% rename from spec/examples/dkim_signing/email.msg rename to spec/examples/dkim_signing/email1.msg diff --git a/spec/examples/dkim_signing/email2.msg b/spec/examples/dkim_signing/email2.msg new file mode 100644 index 0000000..d0d2256 --- /dev/null +++ b/spec/examples/dkim_signing/email2.msg @@ -0,0 +1,1016 @@ +domain: adamtest.viaduct.io +time: 1627490307 +dkim_identifier: postal-R7w1LN +private_key: | + -----BEGIN RSA PRIVATE KEY----- + MIICWwIBAAKBgQCwc2EEPeNKe1jS4cQ0GQXeRkm8vsDsD3UeR9EUdxLuvbzJ2VvZ + tRyFVLkUMmQ0WjOLZ+DU3u4CjfGp/xuNDJROmYd3itz7FKRxvOIGCYwu7ka5GSqP + V/aXyWRWalbo5RPbjfImnHGkKzYlTzvd7p+MkhY+0pCeXnWDWD9IVcGHjQIDAQAB + AoGAJj98Yi0AHd8K6/tgSmK6MOpPhYhbzU+0dXHf0m3VPscGK0LgdBqcKhKpY8Vg + jzCWR7umsr34HbmjDtRrpnF5nAuoevuK0CYI5a2u2fnc1Qygq4M3Ydq4MtKDA2Fs + i6b+h+DUpn2YRX1fYLAVIwJiRi0qYuDX63BdT0jsuaQyRAkCQQDlK+NTpVY3A1tu + wncAmax3gap3fmapZOEGhKIK+zHP3w13gztQdjcJ6v/5RMemiqYTKJcrlCEYFYGF + z94JvUs3AkEAxRt8gA9kQ8l1VcpdGurRAduCG/raeIrpD9MXlfY9c8+V+65mVjQ+ + WuhbJ6fQHkA2MVuUWR+EJ1SELbDtgYoNWwJAGKxw/UB/18x0u6gUR+xDtVowkEz7 + oKFL2PfOun/xDQBm4scuS6tuoZK7nIrbNAMZflaQcBCyv3URTObkcQgAYQJACG4j + hgqifC+6n/+2ubb/V3f++ZliDLPMQgwCPzy35iMjxA7ye49id1rmwyxvP0v5xWSo + VKN/cHsx6A5gKiEwbwJAV1Ll5Xqfj6p92rSXXP/cHG5cEvYFsPgYRPMd6qgVRvoQ + 8CZWA1vhnm6M/tB7UExROAuqexsDrOlTPrphLEcMdg== + -----END RSA PRIVATE KEY----- +headers: content-transfer-encoding:content-type:to:message-id:date:mime-version:reply-to:from:subject:list-unsubscribe:list-id +bh: z/984HsxoQhYgMjcdqgVI00vVOHB5H85L6FE9/7IG3k= +b: AUgfU59IxHLLciftQ6eTuCabZp6ui5BoKxbfhN31yCR7YqRQM3I3vVxfu653zztyC2LbWVZ1oLPSCD/UlDKRtqWUtjXrI/br+7SmMRwv4VyCzpVeXp25w+f6UR1Y8VGdfh/Q2sfqZ1Sop5g6DdGpv1m5abKJ3/onX6vt79ZIMwA= +--- +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset="UTF-8" +To: gf1gzhnlUUZ3Zo@dkimvalidator.com +Message-ID: +Date: Wed, 28 Jul 2021 05:10:19 +0000 +MIME-Version: 1.0 +Reply-To: mail@reply.perfect-quotes.com +From: "Birchmore Property" +Subject: Hassle-free buy-to-let opportunity with 8.5% NET returns +X-Report-Abuse: mail@reply.perfect-quotes.com +List-Unsubscribe: +List-Id: + + + + + + + + + + + +=0D +
=0D + + = + +
+ + + + + + + + + + + + + + + +
= + + + = + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+
+
Invest in the= + UK's best performing asset class
+
=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=C2= +=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2= +=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2= +=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0 =C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0 =C2=A0=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0 = +=C2=A0=C2=A0 =C2=A0=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2= +=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0 =C2=A0=E2=80=8C= +=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C= +=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C= +=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C= +=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C=C2=A0=E2=80=8C= +=C2=A0 =C2=A0
+
+

ADs | Add Perfect Quotes to your address book | Unsu= +bscribe

+
+ + + + + +
+ + + + + +
= + 3D"The
+ + + + + + + +
+ + + + + +
+ + + +
+ + + + + +
+ + + +
Phase 2 Now Released!
+ + + + + + + +
+ + + + + +
+ + + +
+ + + + + +
+ + + +
8.5% NET Returns Guaranteed For 3 Yea= +rs
+ + + + + +
+ + + +
+ + + +
The Villas is a b= +rand-new investment opportunity in the student accommodation sector, idea= +lly located in Stoke-on-Trent to meet the huge demand from the 25,000+ st= +udents at the city=E2=80=99s Keele and Staffordshire Universities. The 17= +4 studio apartments offer spacious, contemporary interiors, with developm= +ent facilities including communal study and relaxation spaces, caf=C3=A9,= + gym, bike storage and car parks. Units start from a low =C2=A374,950, wi= +th furniture included within the price and 8.5% NET returns guaranteed fo= +r the first 3 years.
+
+ + + + +
The Villas is a Cash-Only Investor Opportunity From Birchmore
+
+ + + + + + +
+ + + + + + +
City-Centre Location
Perfectly situated in the
= + + centre of Stoke-on-Trent,
+ ensuring maximum appeal to
+ the city=E2=80=99s student populati= +on
+ + + + + + + +
+ + + + + + +
Hands-Off Investment
Fully managed by Homes
+ For Students, one of the UK=E2=80=99= +s
+ leading providers of quality
+ student accommodation
+ + + + + + +
+ + + + + + +
FURNITURE INCLUDED
Full furniture packs included
+ in the purchase price,
+ providing both value and
+ convenience for investors
+ + + + + + + +
+ + + + + + +
4% Paid On Deposits
Interest paid on reservation
+ deposits from exchange until
+ the development completes
+ in September 2022
+ + + + + + + + + + +
+ + + + + +
+ + + +
REQUEST YOUR BROCHURE
+ + + + + = + + = + + = + + = + + = + + + = + + + + + +
=0D +
=0D +
You are receiving message 34782869 = +on your email address from DataSoftSolutions LP, 64 Cumberland Street, Ed= +inburgh, UK
=0D +because you are on Time Travel Promotion LP's list of managers and profes= +sionals under controller ID AemvJOxOfPgAZzD2GsN4.
=0D +You have the right of access, rectification, opposition and consent for y= +our data which you can access under Privacy policy.
=0D +To stop receiving Special Offers by email for your professional activity<= +br style=3D"line-height:100%;">=0D +or if you wish to personalize your experience follow the data controller = +page.=0D +
=0D +
+ = + + + + +
+ +=0D +3D""=0D +

3D''

+=0D +=0D diff --git a/spec/lib/postal/dkim_header_spec.rb b/spec/lib/postal/dkim_header_spec.rb index b440fa5..bc94280 100644 --- a/spec/lib/postal/dkim_header_spec.rb +++ b/spec/lib/postal/dkim_header_spec.rb @@ -10,7 +10,7 @@ describe Postal::DKIMHeader do frontmatter, email = contents.split(/^---\n/m, 2) frontmatter = YAML.load(frontmatter) email.strip - it "works with #{path.split('/').first}" do + it "works with #{path.split('/').last}" do mocked_time = Time.at(frontmatter['time'].to_i) allow(Time).to receive(:now).and_return(mocked_time)