Skip to content

Content-Type: multipart/mixed seems to force base64 encoding somehow in Dkim.sign(mail) #32

@jschoch

Description

@jschoch

I have a huge message from aliexpress that when passed through Dkim.sign comes out encoded as base64 and gmail doesn't really like it. If i change the content type to "multipart/alternative" it doesn't end up as base64. I tried to shink it down but that doesn't impact it.

here's the test msg redacted a bit

Received: from out24-13.mail.alibaba.com (out24-13.mail.alibaba.com [115.124.24.13])
        by myemail.net (Postfix) with ESMTP id C0EE340438
        for bob@bob.com; Mon,  8 Nov 2021 14:05:19 +0000 (UTC)
DKIM-Filter: OpenDKIM Filter v2.10.3 myemail.net C0EE340438
Authentication-Results: myemail.net;
        dkim=pass (1024-bit key) header.d=mail.aliexpress.com header.i=@mail.aliexpress.com header.b=aqadJZh+
X-AliDM-RcptTo: YWI1MzdjMWE5NzRmMzQ0YzU4Yzc5ZjU1ZDRmYWI1NDk4QGJybmcudXM=
Feedback-ID: default:present_ae@mail.aliexpress.com:batch:13
DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=mail.aliexpress.com; s=s1024;
        t=1636380318; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type;
        bh=ir/1fYnPPk+nKtectnb5YsqowhiW9rE7NTu4dGwaXeY=;
        b=aqadJZh+vBA1XUX2bye/ZDsukKYQaOOqpTb9NJVYc4qe+dKpNxs2rpdKQVFc/p0OouHn4NAmeRv3rRqzmS8TUdEAAMCplHhBoAEs9UN1nWLQ0M0YcM14O1SySV4W/5wTpAzM/Q7ytLXh4Yx/0DN/h00/6cA8NvDZX2LTlPo2xWI=
X-EnvId: 194285051284
Received: from ae-buyer-user9f74-xxfn8(mailfrom:present_ae@mail.aliexpress.com fp:SMTPD_----0owGdlt)
          by smtp.aliyun-inc.com(127.0.0.1);
          Mon, 08 Nov 2021 22:05:17 +0800
Date: Mon, 8 Nov 2021 06:05:17 -0800 (PST)
From: AliExpress <present_ae@mail.aliexpress.com>
To: bob@bob.com
Message-ID: 3197biz_price_reduce_edm:0:0_4659037$074e0a7ae314499f960e4e47fa388cfa
Subject: New price alert for bob
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="----=_Part_133763949_30120080.1636380317614"

------=_Part_133763949_30120080.1636380317614
Content-Type: text/html;charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!--aeug_edm_19435#${houyiJobId}--><!doctype html>
<html xmlns=3D"http://www.w3.org/1999/xhtml" xmlns:v=3D"urn:schemas-microso=
ft-com:vml" xmlns:o=3D"urn:schemas-microsoft-com:office:office">
 <head>=20
  <meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=3D=
1">=20
 </head>=20
 <body style=3D"background: #fff; background-color: #fff;">=20
 
  </div> =20
 </body>
</html><div style=3D"display:none"><img style=3D"display:none" src=3D"http:=
//ae.mmstat.com/ae.edm.edm_open?tracelog=3Drowan-ae_usertouch-aeug_edm_1943=
5_1_en_US-2021-11-08&rowan_msg_id=3D3197biz_price_reduce_edm:0:0_4659037$07=
4e0a7ae314499f960e4e47fa388cfa"/></div>
------=_Part_133763949_30120080.1636380317614--

here's the code that calls the signing

def sign(mail_pipe) do
    
    if mail_pipe.domain == :error, do: raise "signing... domain error"
    
    [rsaentry] =  :public_key.pem_decode(File.read!(@privkey))   
    new_mail = %MimeMail{headers: mail_pipe.stripped_headers,body: mail_pipe.new_mm.body}
    
    to_addresses = Enum.map(mail_pipe.to_list, fn(x) ->
      x.new.address
    end)
    key = :public_key.pem_entry_decode(rsaentry)

    #
    #  Seems fine until this point and it gets base64 encoded
    #
    signed_mail = DKIM.sign(new_mail,key,d: mail_pipe.domain,s: "mail")
    
    raw_signed_mail = MimeMail.to_string(signed_mail)

    Idg.MP.print_report(mail_pipe)
    r = {mail_pipe.from.new.address,to_addresses,raw_signed_mail} 
  end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions