msg:append_text_html() breaks messages with base64 Content-Transfer-Encoding

It seems like calling msg:append_text_html() breaks the message content if Content-Transfer-Encoding is base64. I used the code below to make sure that it’s append_text_html that’s causing this:

  if (track_opens and track_opens_header ~= "false") or track_opens_header == "true" then
    if aha.cached_domain_has_tracking(domain) then
      local my_tracking_link = string.format('<img src="https://t.%s/msg/%s/images/image.png" alt="t">', original_sender_domain, msg:id())
      local f1 = io.open("/tmp/before-append-text.eml", "w")
      f1:write(msg:get_data())
      f1:close()
      msg:append_text_html(my_tracking_link)
      local f2 = io.open("/tmp/after-append-text.eml", "w")
      f2:write(msg:get_data())
      f2:close()
    end
  end

The message in before-append-text.eml is fine, the one in after-append-text.eml is garbled.

I can share the eml files privately if that helps.

More info, in after-append-text.eml there are two Content-Transfer-Encodings:

--===============1072981469387223509==
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Type: text/html;
    charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html><html lang=3D"fa"><head>=0A    <meta charset=3D"utf-8"/> <!-=
- utf-8 works for most cases -->=0A    <meta name=3D"viewport" content=3D"w=
idth=3Ddevice-width"/> <!-- Forcing initial-scale shouldn't be necessary --=
...

Same part of the message in before-append-text.eml:

--===============1072981469387223509==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64

PCFET0NUWVBFIGh0bWw+PGh0bWwgbGFuZz0iZmEiPjxoZWFkPgogICAgPG1ldGEgY2hhcnNldD0i
dXRmLTgiLz4gPCEtLSB1dGYtOCB3b3JrcyBmb3IgbW9zdCBjYXNlcyAtLT4KICAgIDxtZXRhIG5h

fixed in mailparsing: fix replace_text_body / msg:append_text_XXX · KumoCorp/kumomta@b0a37c7 · GitHub