Skip to content

Commit

Permalink
Remove extra new line on multipart encoding (#260) (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
xadhoom authored May 3, 2021
1 parent 3f916de commit 18ad70d
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/mimemail.erl
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ encode_component(_Type, _SubType, Headers, _Params, Body) ->

encode_component_part({<<"multipart">>, SubType, Headers, PartParams, Body}) ->
{FixedParams, FixedHeaders} = ensure_content_headers(<<"multipart">>, SubType, PartParams, Headers, Body, false),
encode_headers(FixedHeaders) ++ [<<>>] ++
encode_headers(FixedHeaders) ++
encode_component(<<"multipart">>, SubType, FixedHeaders, FixedParams, Body);
encode_component_part({Type, SubType, Headers, PartParams, Body}) ->
PartData = case Body of
Expand Down Expand Up @@ -1528,6 +1528,16 @@ parse_example_mails_test_() ->
?assertEqual(?IMAGE_MD5, erlang:md5(element(5, Image)))
end
},
{"alternative text/html with calendar attachment.",
fun() ->
Decoded = Getmail("message-text-html-attachment.eml"),
?assertMatch({<<"multipart">>, <<"mixed">>, _, _, [
{<<"multipart">>, <<"alternative">>, _, _, [
{<<"text">>, <<"plain">>, _, _, _},
{<<"text">>, <<"html">>, _, _, _}]},
{<<"text">>, <<"calendar">>, _, _, _}]}, Decoded)
end
},
{"Outlook 2007 with leading tabs in quoted-printable.",
fun() ->
Decoded = Getmail("outlook-2007.eml"),
Expand Down Expand Up @@ -1950,6 +1960,10 @@ rfc2047_decode_test_() ->
].

encoding_test_() ->
Getmail = fun(File) ->
{ok, Email} = file:read_file(filename:join("test/fixtures/", File)),
decode(Email)
end,
[
{"Simple email",
fun() ->
Expand Down Expand Up @@ -2080,6 +2094,14 @@ encoding_test_() ->
Result)
end
},
{"multipart/mixed email with multipart/alternative does not add an extra empty lines",
fun() ->
Email = Getmail("message-text-html-attachment.eml"),
Encoded = encode(Email),
Re = re:run(Encoded, "(?:\\r\\n){3}", [global, {capture, all, binary}]),
?assertMatch({match, [_]}, Re)
end
},
{"Missing headers should be added",
fun() ->
Email = {<<"text">>, <<"plain">>, [
Expand Down
57 changes: 57 additions & 0 deletions test/fixtures/message-text-html-attachment.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Return-Path: <[email protected]>
From: [email protected]
To: [email protected]
Subject: A message with text, html and a calendar attachment
Reply-To: [email protected]
Mime-Version: 1.0
Sender: [email protected]
Content-Type: multipart/mixed;
boundary="_=4g116a4p31245o2q4h634e3y354m3103=_"
Date: Tue, 27 Apr 2021 12:45:20 +0200
Message-ID: <[email protected]>


--_=4g116a4p31245o2q4h634e3y354m3103=_
Content-Type: multipart/alternative;
boundary="_=513719676i276h6k6a4h1j326j3m5c32=_"
Content-Disposition: inline
--_=513719676i276h6k6a4h1j326j3m5c32=_
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
some text
--_=513719676i276h6k6a4h1j326j3m5c32=_
Content-Type: text/html;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<html></html>
--_=513719676i276h6k6a4h1j326j3m5c32=_--

--_=4g116a4p31245o2q4h634e3y354m3103=_
Content-Transfer-Encoding: base64
Content-Id: <calendar.ics>
Content-Type: text/calendar;
method="REQUEST"
Content-Disposition: inline
QkVHSU46VkNBTEVOREFSDQpQUk9ESUQ6LS8vS0JSVy8vQ2FsaWJleCAwLjEuMC8vRU4NClZFUlNJ
T046Mi4wDQpDQUxTQ0FMRTpHUkVHT1JJQU4NCk1FVEhPRDpSRVFVRVNUDQpCRUdJTjpWRVZFTlQN
CkxBU1QtTU9ESUZJRUQ6MjAyMTA0MjdUMTA0NTIwWg0KU0VRVUVOQ0U6MA0KRFRTVEFNUDoyMDIx
MDQyN1QxMDQ1MjBaDQpDUkVBVEVEOjIwMjEwNDI3VDEwNDUyMFoNClNVTU1BUlk6QSB0ZXN0IGV2
ZW50DQpPUkdBTklaRVI7Q049c2V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